I'm having a problem similar to this post, but I am already running the latest version of virtualenv and I also get a different ImportError.
Using virtualenv with version 2.7 (default) works fine but I need to use python3 for another project. I installed it using brew install python3 in OSX 10.10.2.
When I try:
> pip install --upgrade virtualenv
Requirement already up-to-date: virtualenv in /Library/Python/2.7/site-packages
Cleaning up...
> virtualenv --version
12.0.7
> virtualenv -p python3 test
I still get:
Running virtualenv with interpreter /usr/local/bin/python3
Using base prefix '/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4'
New python executable in venv/bin/python3.4
Also creating executable in venv/bin/python
Failed to import the site module
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/site.py", line 73, in <module>
__boot()
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/site.py", line 2, in __boot
import sys, imp, os, os.path
File "/Users/user/Desktop/project/studyprocessor/venv/bin/../lib/python3.4/imp.py", line 22, in <module>
from importlib import util
File "/Users/user/Desktop/project/studyprocessor/venv/bin/../lib/python3.4/importlib/util.py", line 12, in <module>
from contextlib import contextmanager
ImportError: No module named 'contextlib'
ERROR: The executable venv/bin/python3.4 is not functioning
ERROR: It thinks sys.prefix is '/Users/user/Desktop/project/studyprocessor' (should be '/Users/user/Desktop/project/studyprocessor/venv')
ERROR: virtualenv is not compatible with this system or executable
Any ideas?
The pip program what you are using corresponds to the Python 2.7 version. You need to use the pip which corresponds to Python 3.x. So, you should be using
pip3 install virtualenv
Alternatively, you can create virtual environments in Python 3.3+ with the venv module, like this
python3 -m venv test
try following
virtualenv --no-site-packages --distribute -p /usr/bin/python3 ~/.virtualenvs/py3
workon py3
Related
First of all, sorry about my english, this isn't my native language.
PS C:\Users\...... wsl ./Test.py
Traceback (most recent call last):
File "./Test.py", line 2, in <module>
from PIL import Image
ModuleNotFoundError: No module named 'PIL'
I made this Test.py using pycharm. Its a wordcloud program and it works fine with pycharm.
However, when I try to execute this file with wsl ./ it shows me the error above. Can someone help?
According to your comment you are checking if Pillow is installed in Windows, but you are running your Windows-hosted Test.py in WSL, i.e. using python interpreter and libraries that are installed in WSL.
To illustrate, Powershell session in Windows, using python libpath from conda:
(base) PS C:\> python -c "import os; print(os.__file__)"
C:\Users\ml\Miniconda3\lib\os.py
Powershell session in Windows, but executing code in WSL, python and libpath from Ubuntu:
(base) PS C:\> wsl python3 -c "import os; print(os.__file__)"
/usr/lib/python3.8/os.py
You do need to check your Pillow installation, but in WSL.
You most likely do not have Pillow installed, and the code wants it to run.
To install it you should just need to run
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade Pillow
or you can follow the instructions on the pillow website
Hope that helps [:
Unable to import a python module as a non root that was installed as root.
I have installed flask_babelex package in both ways:
pip3 install --user flask_babelex
pip3 install flask_babelex
and working fine when I try to import:
[root#dev-apache ~]# python3 -c "import flask_babelex"
It's not working if were I run as a non-root user:
[root#dev-apache ~]# su - apache
-bash-4.2$
-bash-4.2$ python3 -c "import flask_babelex"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'flask_babelex'
I tried by changing permission to site-packages but no use:
/usr/local/lib/python3.6/site-packages
any workaround suggestions?
You can ensure you're installing the package with the correct python environment by running
python3 -m pip install flask_babelex
This will install the package specifically in the environment that your python3 is using
After I upgraded pip from 8.1.1 to 19.0.1 by running
pip install --upgrade pip
I tried to test the version of pip by running
pip -V
But I got the following error
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
from pip import main
ImportError: cannot import name 'main'
I set the python3 and pip3 to be default by putting the following in ~/.bashrc
alias python=python3
alias pip=pip3
My system is ubuntu 16.04
This is a common issue as referenced here : https://github.com/pypa/pip/issues/5221
You are trying to use the pip, which is shipped with the Debian system. You better try to avoid using that pip at any cost.
Please use python3 -m pip install package instead of the system pip which you have in the debian system.
I also recommend using venv - virtual environments for keeping your system environment safe.
I am trying to install something using "python setup.py install" but it shows me this error :-
Traceback (most recent call last):
File "setup.py", line 3, in <module>
from setuptools import setup
ImportError: No module named setuptools
I have installed this missing module using "pip install setuptools". But still it shows me the same error .I have also tried to install this using "sudo apt-get install python-setuptools" but the problem still remains the same. Help me in this issue
If you have Python 2 >=2.7.9 or Python 3 >=3.4 installed from python.org, you will already have pip and setuptools, but will need to upgrade to the latest version:
On Linux or macOS:
pip install -U pip setuptools
On Windows:
python -m pip install -U pip setuptools
If you’re using a Python install on Linux that’s managed by the system package manager (e.g “yum”, “apt-get” etc…), and you want to use the system package manager to install or upgrade pip, then see link
I have installed virtualenv
sudo pip3 install virtualenv
Then created a new virtualenv
virtualenv --python=/usr/bin/python3.5 venv
It returned
Running virtualenv with interpreter /usr/bin/python3.5
Using base prefix '/usr'
New python executable in /home/alexandra/Documents/online-store/venv/bin/python3.5
Also creating executable in /home/alexandra/Documents/online-store/venv/bin/python
Installing setuptools, pip, wheel...done.
Activated it
source venv/bin/activate
Then installed Django
sudo pip3 install django
It installed there (that is what sudo pip3 install django --upgrade returned)
/usr/local/lib/python3.4/dist-packages
Maybe that's the problem? Because it installed in python3.4 and not python3.5. But how to install Django in python3.5?
In file manage.py there is a path to python3.5 in this virtualenv.
Then I run
python manage.py runserver
It returns an error
Traceback (most recent call last):
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named 'django'
Can anyone help me?
When using pip to install packages inside the virtual env, do not sudo. It makes packages be installed globally. Simply remove sudo from beginning of the command and it should install it in the venv you are currently working on.
You installed django into a system python 3.4.
When you ran install command first time without sudo, did it complain about permissions? That should have been your clue that it's not the right pip. My guess is pip3 only exists in system python and not your virtualenv. You can use which to find out, but this will work in any case:
venv/bin/pip install django
Don't do sudo and just use pip for installing all the packages. You have already installed python3 in your virtualenv, so there is no need of using pip3.
Just do e.g. pip install django. or for other packages pip install <package_name>