How do I install curses library in my editor? - python-3.x

I cannot install the curses library in my Editor. Is there some other way to make sure I have the library installed and can import it?
I'm trying to build a tictactoe game using venv, in Pycharm Community Edition. I imported curses in the directory where my scripts are located using command prompt. I can import curses in IDLE editor. However, there is no package called curses in the Settings->Project Interpreter.
pip install curses‑2.2‑cp36‑cp36m‑win_amd64.whl
this throws an error:
Requirement 'curses-2.2-cp36-cp36m-win_amd64.whl' looks like a
filename, but the file does not exist
curses-2.2-cp36-cp36m-win_amd64.whl is not a supported wheel on this
platform.
Edited the configurations and checked the checkbox with emulate terminal in output console, still won't work.

You should use:
pip install https://download.lfd.uci.edu/pythonlibs/n5jyqt7p/curses-2.2.1+utf8-cp37-cp37m-win_amd64.whl
The section of the pip command line installer:
cp37 == CPython 3.7
So you need the appropriate whl install file for your installed Python environment.

Related

Using Homebrew python3 with both homebrew packages and pip/pip3 packages in Visual Studio Code for Mac OS

I am currently trying to setup Visual Studio Code on Mac OSX 10.13.6 for coding in python3. I'd like to avoid using multiple virtual environments for my different python3 scripts and instead have them all run using:
(1) the same homebrew installation of python3
(2) accessing installed python packages in:
homebrew packages list
pip3 installed package list
pip installed packages list.
First, I first installed python3 using homebrew:
$ brew info python
python: stable 3.7.7 (bottled), HEAD
Interpreted, interactive, object-oriented programming language
https://www.python.org/
/usr/local/Cellar/python/3.7.7 (4,062 files, 62.4MB)
...
Python has been installed as
/usr/local/bin/python3
...
You can install Python packages with
pip3 install <package>
They will install into the site-package directory
/usr/local/lib/python3.7/site-packages
Second, I installed my required packages using homebrew:
$ brew list
cmake libffi p11-kit
dcraw libheif pandoc
dlib libidn2 pcre
...
jasper numpy webp
...
And other packages using pip and pip3:
$ pip list
DEPRECATION:...
Package Version
-------------------------------------- --------
altgraph 0.10.2
...
numpy 1.8.0rc1
...
zope.interface 4.1.1
$
$ pip3 list
Package Version
------------------ -------
appnope 0.1.0
...
numpy 1.18.2
pandocfilters 1.4.2
parso 0.5.2
pexpect 4.7.0
pickleshare 0.7.5
pip 20.0.2
pomegranate 0.12.2
...
scipy 1.4.1
Third, I opened Visual Studio Code and in "Preferences" -> "Settings" and set "Python:Python Path" to the homebrew python3 installation as noted above /usr/local/bin/python3.
See this screenshot:
Next, I added /usr/local/lib/python3.7/site-packages per the homebrew install of python3 to the Visual Studio Code Settings file using:
"python.autoComplete.extraPaths": [
"/usr/local/lib/python3.7/site-packages" ]
Finally, I selected my python interpreter in Visual Studio Code as /usr/local/bin/python3 and tried to run the following 2-lines of imports in a .py script as per the screenshot below. Note that the interpreter is Python 3.7.0 64-bit given by the bottom left corner of the VS Code window.
And after all of that, ended up with this output after clicking the "Play" button to run the code in the top right corner of VS Code:
[Running] python -u "/Users/...bayes_net_nodes.py"
Traceback (most recent call last):
File "/Users/...bayes_net_nodes.py", line 1, in <module>
import numpy as np
ModuleNotFoundError: No module named 'numpy'
[Done] exited with code=1 in 0.037 seconds
What would be the most simple way to configure VS Code so I can run python3 scripts that have access to the all the packages I've installed across my system without using virtual environments? Thank you!
Note: One workaround that seems to work, and I'm not sure why is if I put a shebang at the top of my script #! /usr/local/bin/python3 and my output then looks like this:
[Running] /usr/local/bin/python3 "/Users/...bayes_net_nodes.py"
[Done] exited with code=0 in 0.051 seconds
Which is odd, because that's different than the output above where I didn't use the shebang but both python interpreters according to VSCode are indeed /usr/local/bin/python3
I was able to reproduce your problem.. but only when I use Code Runner to run.
Those kind of Output logs with [Running] and [Done] is Code Runner.
The play button is also not green, indicating Code Runner because the default is green.
Now, for the fix!
You'll notice that it executed your script using python -u. That python would be whatever python means on your system, which for me is the default Python 2.7. Basically, it's not your Homebrew Python3 with numpy.
Code Runner has a default set of "executors" which tells it which executable to use for which language. Search it for in your settings as "code-runner Executor Map":
Open your settings.json, enter code-runner.executorMap, then let it auto-complete with the default. You'll then see a long list of mappings between language and executor. Look for the one for python:
"code-runner.executorMap": {
"javascript": "node",
...
"python": "python -u",
"perl": "perl",
...
}
And there it is: python -u, the same one it used to run your script.
If you want to continue using Code Runner, simply change it to the whichever python interpreter you want to use. In your case, it should be /usr/local/bin/python3:
"code-runner.executorMap": {
...
"python": "/usr/local/bin/python3",
...
}
It should now work:
The reason it works with a #! /usr/local/bin/python3 shebang is because Code Runner has a setting that it respects the file's shebang (code-runner.respectShebang) which is true by default.
If you don't want this extra step of setting-up Code Runner, you can simply disable (or uninstall it). All the steps you already did (setting python.pythonPath, selecting the interpreter, and clicking that Play button) would have already worked just fine with Microsoft's Python extension. See the official docs on running Python files, selecting environments, and debugging.

Kivy Installation Guide for Windows 10

I've been trying to follow online youTube videos to install kivy on my Windows 10 computer (python-3.7.5-amd64, kivy 1.11.1). Aside from the fact that they seem to have different variations on how they approach the topic, I am unable to get a solution that operates satisfactorily.
These are the steps I am following:
I install python (python-3.7.5-amd64.exe) to C:\Python37
I modify the path to include to include the following: C:\Python37\Scripts;C:\Python37;C:\Python37\Libs;C:\Python37\DLLs;C:\Python37\Lib\site-packages;
I added the following environment variable PYTHONPATH = C:\Python37\DLLs;C:\Python37\Libs;C:\Python37;C:\Python37\Scripts;C:\Python37\Lib\site-packages;
I open a command window and type in the following commands (taken from kivy.org)
python -m pip install --upgrade pip wheel setuptools virtualenv
python -m pip install docutils pygments pypiwin32 kivy_deps.sdl2==0.1.* kivy_deps.glew==0.1.*
python -m pip install kivy_deps.gstreamer==0.1.*
python -m pip install kivy_deps.angle==0.1.*
python -m pip install kivy==1.11.1
python -m pip install kivy_examples==1.11.1
I try to run a simple program. From within Windows Explorer I right click the code file (label.py) and from the shortcut menu select python.
A windows pops up for an instant and a directory called __pycache__ gets created with kivy.cpython-37.pyc. Double clicking that causes the program to run.
Is it possible to have a easier solution in which the source code, once compiled executes?
If I open a command prompt and attempt to execute the source code using the command python label.py I get the following:
Traceback (most recent call last):
File "label.py", line 1, in <module>
from kivy.app import App
File "C:\Users\chrib\Google Drive\_Software\Python_Kivy\kivy.py", line 1, in <module>
from kivy.base import runTouchApp
ModuleNotFoundError: No module named 'kivy.base'; 'kivy' is not a package
Why should this happen?
Also is it possible to have a cleaner development environment. I am used to Visual Studio IDE and it would be great if I can use this environment.
Thanks
Code for label.py
from kivy.app import App
from kivy.uix.label import Label
class MyApp(App):
def build(self):
return Label(text='Hello world!');
if __name__=='__main__':
MyApp().run();
I've been trying to follow online youTube videos to install kivy on my Windows 10 computer
Have you tried simply following the instructions on kivy.org? There's no need to use youtube videos, the installation is largely a normal python module install.
I try to run a simple program. From within Windows Explorer I right click the code file (label.py) and from the shortcut menu select python.
Don't do this, run the file by opening a command prompt and typing python yourfilename.py. That way you will see the full traceback for any errors that occur.
A windows pops up for an instant and a directory called pycache gets created with kivy.cpython-37.pyc. Double clicking that causes the program to run.
It sounds likely that the first run is crashing. As above, you want to get the information about why.
Is it possible to have a easier solution in which the source code, once compiled executes?
When you run the code it does execute. As above, it's probably crashing.
ModuleNotFoundError: No module named 'kivy.base'; 'kivy' is not a package
Have you made a file named kivy.py? It looks likely that you have, and that this file is being imported in preference to the installed kivy module.
Also is it possible to have a cleaner development environment. I am used to Visual Studio IDE and it would be great if I can use this environment.
I'm not sure what you consider unclean about your development environment, but you should think in terms of python environments and their installed packages. Kivy is just a python module that you install into a python environment. When you use an IDE, it may integrate with one or more python environments (with options to switch between them). There's nothing special about using Visual Studio with Kivy, just do whatever you normally do to use it with Python.
I figured it out. I had a program in the code directory called kivy.py. I renamed that and it worked.

Need help to install curses for python 3.x with pycharm

Im trying to install curses for windows python 3.x with pycharm. i installed windows curses via pip. but if i import it, theres just message saying no module found.
In terminal/cmd
python -m pip install windows-curses
Requirement already satisfied
then if i type...
c:/.../.../python
import curses
curses.initscr()
i get a blank screen
but importing in python console or as script is not possible. no module found.
Any advises to globaly use import and not just in terminal/cmd.
Thanks
Open Pycharm>Settings>Project Interpreter. Click on the plus icon at the top right.In search type curses or any library which you want to install. Don't forget to check the 'Install to user's site package directory' box.

Unable to import Libraries even though Installed in Anaconda on Pycharm

I am using Ubuntu 18.10(dual Boot win10), I have installed anaconda (conda version- 4.6.7) on ubuntu. After this Installation I installed Pycharm via snap on Command Prompt. Since Pycharm(version - 2018.3.5) didnt Detect my python Location automatically I set the python Interpreter via
Adding Location ->System Interpreter (As I didn't want any Venv) -> Path
But when I try to import opencv in Pycharm it says
ModuleNotFoundError: No module named 'cv2'
Python3.6 in Anaconda Bin is shown to which I have linked in Pycharm (I have also tried other Python files there as well but no luck)
When I run in Terminal: python3 -c 'import sys; print(sys.path)'
It shows:
['', '/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6
/lib-dynload', '/usr/local/lib/python3.6/dist-packages', '/usr/local
/lib/python3.6/dist-packages/setuptools-39.1.0-py3.6.egg', '/usr/lib`/python3
/dist-packages']
So could anyone help me out in this?? Thank You in Advance!!
Edit 1:
I am also unable to access any of the libraries from terminal Itself. So Could anyone help me with that as well. Should I export path of this Python in Anaconda bin folder to bashrc file in Ubuntu?
Edit 2:
The libraries affected is not just opencv. There are few other Libraries like Portaudio which are affected as well along with Opencv

How to change .py to .exe

I made a program in python which is in .py format. However, I would like it to be in .exe
The options I have found are:
py2exe
pyinstaller
The problems with those 2 are because I am running python 3.6 and those 2 programs do not support it, HELP!
Python 3.6 still isn't supported by Pyinstaller. So in order to use it you're gonna need Python 3.5 or below. So, you might wanna change your python version to 3.4 or 2.7. Then you can follow the procedure for creating the exe with pyinstaller. Also I think pyinstaller is a better option than py2exe.
However to make things work without switching to other versions, you might wanna try using cx_freeze:
1.Install the latest version of cx_freeze by pip install cx_Freeze.
2.Create a new python file named ‘setup.py’ on the current directory of your script.
3.On the setup.py, code this and save it:(here my prog.py refers to your .py file name)
from cx_Freeze import setup, Executable
base = None
executables = [Executable("my prog.py", base=base)]
packages = ["idna"]
options = {
'build_exe': {
'packages':packages,
},
}
setup(
name = "<any name>",
options = options,
version = "<any number>",
description = '<any description>',
executables = executables
)
4.With shift pressed right click on the same directory to open a command prompt window.
5.Type: python setup.py build.
6.Check the newly created folder ‘build‘. Within that folder you can able to find your application.
pyinstaller
pip install pyinstaller
Basic usage is very simple, just run it against your main script:
pyinstaller /path/to/yourscript.py
cx_Freeze
pip install cx-Freeze
auto-py-to-exe
pip install auto-py-to-exe
Then to run it, execute the following in the terminal:
auto-py-to-exe
With a simple google search, I found this question which gives a link to a version of py2exe which happens to support python 3.3 and up. Here is the link!
On that page you will find the following bit of information:
Py2exe is a distutils extension which allows to build standalone Windows executable programs (32-bit and 64-bit) from Python scripts; Python 3.3 and later are supported. It can build console executables, windows (GUI) executables, windows services, and DLL/EXE COM servers.
Notice:
Python 3.3 and later are supported.
I have created a batch file to do the work, but first, go to https://datatofish.com/add-python-to-windows-path/ and add python to your path.
Then create a new notepad file with this:
SET /P _input1= Enter the file directory:
cd %_input1%
SET /P _input2= Enter the file name:
pyinstaller --onefile %_input2%
ECHO The exe file is in the dict folder in %_input1%
pause
Save this as a .bat file anywhere and run it.
Enter the directory of the python script.
then the name.
Hope this helps!

Resources