I'm trying to get wxPython to work in a pyenv-based virtualenv with the virtualenv and virtualenvwrapper plugins on MacOS. I've read several questions about making this work, but most of the answers seem to assume that I'm using the system python version, and/or only address one aspect of a broken setup. I haven't yet seen anything that explains what wxPython is checking for when it starts.
I have python 3.7 compiled by pyenv with --enable-framework.
env PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 3.7.4
pyenv itself is installed in my homedir from a reasonably recent (within the last couple of weeks) pull from git.
To be clear, none of the tools or libraries in my Python toolchain are installed by Homebrew.
My virtualenv has access to the framework by virtue of --system-site-packages. Having access to the framework and to the display are supposedly all that's required for wxPython to work, yet I'm still getting the same error on start of any test app:
This program needs access to the screen. Please run with a
Framework build of python, and only when you are logged in
on the main display of your Mac.
It looks to me like everything I should need is available.
% pyenv which python3.7
/Users/matt/.pyenv/versions/3.7.4/bin/python3.7
% mkvirtualenv --system-site-packages --python python3.7 wxtest
Running virtualenv with interpreter /Users/matt/.pyenv/shims/python3.7
Already using interpreter /Users/matt/.pyenv/versions/3.7.4/Python.framework/Versions/3.7/bin/python3.7
Using base prefix '/Users/matt/.pyenv/versions/3.7.4/Python.framework/Versions/3.7'
New python executable in /Users/matt/.ve/wxtest/bin/python3.7
Also creating executable in /Users/matt/.ve/wxtest/bin/python
Installing setuptools, pip, wheel...
done.
virtualenvwrapper.user_scripts creating /Users/matt/.ve/wxtest/bin/predeactivate
virtualenvwrapper.user_scripts creating /Users/matt/.ve/wxtest/bin/postdeactivate
virtualenvwrapper.user_scripts creating /Users/matt/.ve/wxtest/bin/preactivate
virtualenvwrapper.user_scripts creating /Users/matt/.ve/wxtest/bin/postactivate
virtualenvwrapper.user_scripts creating /Users/matt/.ve/wxtest/bin/get_env_details
% python -m site
sys.path = [
'/Users/matt/devel/wxtest',
'/Users/matt/.ve/wxtest/lib/python37.zip',
'/Users/matt/.ve/wxtest/lib/python3.7',
'/Users/matt/.ve/wxtest/lib/python3.7/lib-dynload',
'/Users/matt/.pyenv/versions/3.7.4/Python.framework/Versions/3.7/lib/python3.7',
'/Users/matt/.ve/wxtest/lib/python3.7/site-packages',
'/Users/matt/.pyenv/versions/3.7.4/Python.framework/Versions/3.7/lib/python3.7/site-packages',
]
USER_BASE: '/Users/matt/.local' (exists)
USER_SITE: '/Users/matt/.local/lib/python3.7/site-packages' (doesn't exist)
ENABLE_USER_SITE: True
% pip install wxPython
Collecting wxPython
[...]
Successfully installed numpy-1.18.0 pillow-6.2.1 six-1.13.0 wxPython-4.0.7.post2
The code for IsDisplayAvailable() is buried in the _core shared object library, so not particularly easy to examine. I'm not a C++ coder, and digging around in the code repository all I've been able to find so far is the docstring in src/_app.i, not the actual code.
On Mac OS X a False return value will mean that wx is not
able to access the window manager, which can happen if logged in
remotely or if running from the normal version of python instead
of the framework version, (i.e., pythonw.)
That list of requirements seem to be satisfied by what I have here. I don't have a pythonw binary, but as the pythonw(1) man page says:
Actually, since Python 2.5, the normal python also allows GUI access, so
python and pythonw are now interchangeable.
Does anyone have an exhaustive list of what wxPython actually expects to find before it runs?
The error you're encountering is likely to be a "brew-hole" (a.k.a homebrew installation/compatibility issue for wxpython v3 and sometimes v4).
To test some issues that might be at hand perform the following in your pyenv:
python --version
python3 --version
How are they installed? Did you use brew?
If brew or any non-anaconda: uninstall all.
Then : reinstall python via the anaconda 2019. (xx >04) packaged version and it gives you 3.7.4 or 3.7.5 depending on what you choose.
reinstall via conda/pip cmd-line the required packages that are not with default install.
Anaconda "base" is your default environment.
Then conda create --name myenv where myenv is any name you give your environment. For example "myPythonwx408" environment.
cmdline: conda activate myenv
... and tada.. up you go...
If the error persist in anaconda env you can post the environment.yml file so I can recreate your environment for testing.
You mention "virtualenv". Is that the actual virtualenv package or just what you are calling the pyenv instance? If the former then try python -m venv instead. The virtualenv package still hides the framework-ness of the parent Python, even after all these years. The venv package is included with Python3 and is a much better/simpler implementation of the concept.
Related
I am using 18.04 Ubuntu with Anaconda.Recently i have trying to install OpenCV through conda-forge channel in the base environment. I did not install purposely any Python version and did not use any pip command either in base environment. Now, in the base environment, if execute just python, i get the same python version as system version and if execute python3 , i get the version installed by conda-forge. Please refer the screen shot. Python_on_Conda_base
I would like to know what is difference between python and python3 command?.What is should i keep in mind? basically i prefer the version 3.7.5 Python
.So, only the Python3 has uses different version. So, question what i should take note when i using python3 some_script.py? what is pros and cons of having this 2 version?
So far,i did not face any issues, but removed the conda-forge channel from Anaconda to avoid any conflicts. Any thoughts?
After posting this question, i have noticed python --version command gives Python 3.7.5 on Conda base environment and Ubuntu terminal (outside Conda)
You most likely have set an alias for python to point to the python3 binary.
Check this by typing type python, which will probably give you
python is aliased to ...
The crux here is that an alias will not be detected by which and as you revealed in the comments your which python returns the correct python version from your conda base environment, which makes an alias the most likely explanation, as PATH issues can be ruled out.
If above command does indeed reveal an alias, then check you .bashrc or similar file that you might have modified for a line alias python=.... Delete it, restart your terminal and everything should work normally
I'm teaching myself python and have been exclusively been using Jupyter Notebooks through Anaconda until now. I'm now trying to move away from Jupyter and write .py scripts in an IDE. While working in Jupyter i've pip installed modules and they've worked fine within Jupyter. I've just discovered though that if i do this through an IDE i get a ModuleNotFoundError.
I've looked online and there are alot of posts with similar issues but none that quite matches mine. While i'm learning actual python code ok there is a huge hole in my knowledge around the setup, the terminal etc, and when i first started out i downloaded different IDE's which may not be helping...
Here's a few things from posts that i've tried that may give a clue as to what's wrong.
1) which python gives me //anaconda3/bin/python
2) which pip gives me //anaconda3/bin/pip
3) in python in the terminal:
import sys
for p in sys.path:
print(p)
//anaconda3/lib/python37.zip
//anaconda3/lib/python3.7
//anaconda3/lib/python3.7/lib-dynload
//anaconda3/lib/python3.7/site-packages
//anaconda3/lib/python3.7/site-packages/aeosa
4) usr/local/bin/ has a bunch of files (not folders) in it like 'Python3.7', 'Python3.7-config' etc
5) which -a pip = //anaconda3/bin/pip
6) which -a python gives me two paths = //anaconda3/bin/python
/usr/bin/python
7) usr/bin/python is a unix executable file, when i click it it opens a python terminal that says Python 2.7.16. within the usr/bin directory all the other python related files seem to reference 2.7.
8) when i pip install i generally just go 'pip install x' at the terminal. I thought maybe i needed to do 'pip3 install x' it would maybe not point just to anaconda, but was a complete guess and while the modules downloaded it didn't help at all.
9) I tried using an alias alias python=/usr/local/bin/python3 - but as python3 isn't actually there, i just created another problem that i then had to 'unalias'
10) pip -V = pip 19.1.1 from //anaconda3/lib/python3.7/site-packages/pip (python 3.7)
11) pip freeze showed the all the modules i would expect to see
This post seemed similar: Modules are installed using pip on OSX but not found when importing
Any help would be greatly, greatly appreciated. I've been learning ok up until now but i'm pretty out of my depth with this side of things, and i can't move forward at all unless i find a way to use an IDE with third party modules...
UPDATE - Tried uninstalling and reinstalling anaconda and it made no difference. All still works in Jupyter, modules can't be found elsewhere from IDEs. Also can't seem to install things like pandas through anaconda as it already has it, so it doesn't seem related to the IDE not being able to find it –
Thanks
When using the Anaconda distribution you should avoid pip as much as possible. Use the conda package manager instead. Try installing missing packages from the conda-forge channel first:
conda install newpackage -c conda-forge
Before you can use Anaconda properly, you need to activate it:
conda activate
The Jupyter start link did this for you. The Anaconda Prompt does the same thing and you can start your IDE directly from there. However, all IDE's manage environments themselfs, which is way more flexible. So it is time well spent to learn your IDE's features first.
I'm a bit new to Python and all its "deployment" related tools: pip3,setuptools, virtualenv wheel etc, so I hope my question will make sense...anyways it is like so:
I have a Python3 project which is "managed" with virtual environment using virtualenv where all the projects' dependencies are "listed" within the project's setup.py file. The contents of the setup.py files are as follows:
setup(name="MyProjectName",
version="0.1",
description="Some description",
url="someURL",
author="My Name",
author_email="someemail",
license="MIT",
packages=find_packages(),
include_package_data=True,
install_requires=["robotframework", "paramiko"])
As you can see, the only 3rd party packages the project uses (explicitly) are robotframework & paramiko.
Now when I'm deploying the project, I do the following actions (in that order):
Create a virtual environment with the command:
virtualenv -p python3 virtualEnvFolderName
Switching "into" the virtual environment like so (I'm deploying it on a Linux machine):
source virtualEnvFolderName/bin/activate
Running the setup.py script with the install argument to "automatically" install all the project's dependencies with the following command:
python3 setup.py install
--> Up until couple of days ago, all the 3rd party packages (and their "dependencies sub-packages") listed in the setup.py file where downloaded (and then installed) using their whl file, i.e. - for example:The output for the paramiko package installation would have been:
Reading https://pypi.org/simple/paramiko/
Downloading https://files.pythonhosted.org/packages/4b/80/74dace9e48b0ef923633dfb5e48798f58a168e4734bca8ecfaf839ba051a/paramiko-2.6.0-py2.py3-none-any.whl#sha256=99f0179bdc176281d21961a003ffdb2ec369daac1a1007241f53374e376576cf
Best match: paramiko 2.6.0
Processing paramiko-2.6.0-py2.py3-none-any.whl
Installing paramiko-2.6.0-py2.py3-none-any.whl to
--> This way, the installation was very quick (~1-3 seconds per package).
Today, when I performed the same procedure, on the same machine (I'm quiet sure I did not change any settings on my Ubuntu 16.04 machine), for each package the setup.py tried to install, it installed "via" the tar.gz file (i.e. sources ?) and NOT using the whl file --> which takes MUCH longer since for some of the packages it actually builds (complies) all the "underlying C libraries". This "change" makes my "installation procedure" execution time increase from ~20 seconds to ~4 minutes.
My questions are:
a) How can I resolve this situation - preferably without changing the deployment procedure, i.e. - still perform the 3 steps mentioned above, taking into account that perhaps one or more of the commands will be slightly modified (the creation of the virtual environment and/or some additional argument in required to the setup.py ? ).
b) If I have no other option, then using a pip3 install -r requirement.txt ... "procedure" will also be good, if it also will use whl file(s) whenever applicable.
c) If I will need to "switch" my virtual environment "generator" to venv it is OK (and actually preferred, in case it will deploy the project in the "same" duration).
NOTES:
I tested it both on Ubuntu 16.04 and Ubuntu 18.04 machines with Python 3.5 and Python 3.6 respectively.
Thanks !!
It seems like there is no wheel compatible with your environment (operating system, Python interpreter version, CPU bitness) for the current version of the project PyNaCl. If you have a recent version of pip, the command path/to/venv/bin/python -m pip debug --verbose should list the tags that are compatible with your environment, so that you can compare with the list of wheels available on PyPI.
I use Pycharm to create and manage my virtualenvs in my projects.
The problem is that after adding a library with pycharm, when I type the command (pip3 freeze --user), the library does not appear in the command result.
I have to manually type the pip install command each time so that the library is visible.
What manipulation should I do in PyCharm to solve this problem?
For what you are saying, the first thing that comes to mind is that you should use:
pip freeze
And not
pip3 freeze
Because the command mapped to the pip version when you have virtualenv activated is the first. Note that for installing you seem to use pip, and not pip3
Moreover, the --user option afaik is related to the packages installed in the user folder:
--user Install to the Python user install directory for your platform. Typically
~/.local/, or %APPDATA%\Python on
Windows. (See the Python documentation for site.USER_BASE for full details.)
If your packages are installed in the virtualenv folder, I would tell you to not use that option.
Also please make sure you have your virtualenv activated. In linux you can do so by source path/to/virtualenv/activate
Edit
I understand that the reason you are using pip3 is because you may have different versions of Python in your machine. Let me explain you a bit further how it works, because version management is usually a headache for many programmers and it is common to find problems when doing so.
If you install different versions of Python in your linux machine, and you do that as root, then the installation will proceed for the whole system. Usually Python2 installation folder for Linux machines is /usr/bin/python. However, I am uncertain of which directory is used for Python3 installations. You can check that easily by doing whereis python3. You can serach the path to binary of any command by doing whereis command. Note that this works also for whereis python as far as you don't have virtualenv activated.
Aditionally, the link to the binary of a command (or the set of instructions to be exectued, more broadly) is defined in certain folders in Linux, depending on whether you created the command as root or as a user, and possibly also on the distro. This works differently in Windows, that uses the Registry Edit utility to handle command mappings. When you enable your virtualenv, what you are doing is creating an environment that enables mapping system commands such as python to the Python installation in your virtualenv folder.
When you disable the virtualenv, the command points again to the default installation path. Same happens with pip, so incorrect usage of this tool may result in different packages being installed in different locations, and therefore not appearing available for the right Python version at any given circumstance.
In Linux, environment variables are shell dependent, though you can write them out with echo $variable and set them with variable=value (from bash). The search path is simply called PATH and you can get yours by typing echo $PATH.
Source: https://askubuntu.com/a/262073/426469
I encourage you to check other questions in SE network such as this: https://unix.stackexchange.com/a/42211/96121, to learn more about this.
Addendum
Quick tip: it is common to use the pip freeze command as follows:
pip freeze > requirements.txt
It is a standard that leads to understanding that modules in such file are required for the correct functioning of your application. That lets you easily exclude the virtualenv folder when you install the program in another computer, since you can readily know the requriments for a fresh installation. However, you can use the command as you want.
I'm using Windows 7 and am up to date on patches. I was using Python 3.5.2 and wanted to upgrade to 3.6, so I went to the Python site, downloaded 3.6.4.exe for Windows, and ran it. The Python seems to work fine and is 3.6.4, but trying to import any of the packages I was using (pandas, numpy, tensorflow, etc) now gives me ModuleNotFoundError: No module named <whichever module it was>. Also, pip list now shows only pip and setuptools.
It appears to be a known issue, for example this from nearly a year ago, which suggests that I should "uninstall the python bindings and install again", but I can't figure out what that means. Fortunately I can still access 3.5.2 by using py -3.5, and then my imports work. Can anyone tell me how to fix this for 3.6 without having to reinstall all my modules manually?
I was thinking possibly I should have upgraded through pip; it seems like that's possible but maybe a bad idea for some reason? On further investigation it looks like what I should have done was save my requirements with pip freeze > requirements.txt, and then after installing the new Python restore them with pip install -r requirements.txt. Is this right?
Hard to say if you have an install problem, but this is what I would try if I were in your place.
Create a virtual environment as per; docs
c:>c:\Python36\python -m venv c:\path\to\myenv
Activate your virtual environment
C:> \Scripts\activate.bat
Run your application from within your activated environment. Each time you get an import error, do a pip-install from within the active environment. (For your own modules, you may need to modify PYTHONPATH in 'activate.bat')
Once you have your application running again, do your pip freeze > requirements.txt, and keep that with your project.
Each time you run your application, do so from within the activated virtual environment.
This will give you a clean requirements.txt that doesn't include a bunch of junk from other projects. Then, when you go to 3.7, just create the virtualenv and run your requirements.txt and wala!
I suspect your issue is simply not running against the correct interpreter, running from within a virtual environment should at least rule it out.