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
Related
When I use pip3 I get this error:
Traceback (most recent call last):
File "/Library/Developer/CommandLineTools/usr/bin/pip3", line 7, in <module>
from pip import main
ModuleNotFoundError: No module named 'pip'
I tried to reinstall PIP but still reported this error, but I use python3 -m ensurepip
It told me to install Xcode command line
$ python3 -m ensurepip
$ xcode-select: Failed to locate 'python3.9', requesting installation of command line developer tools.
I had this problem when I was trying to update the pip and it failed.
This always works for me:
Download the script, from https://bootstrap.pypa.io/get-pip.py.
Open a terminal/command prompt, cd to the folder containing the get-pip.py file and run:
python get-pip.py
font: https://pip.pypa.io/en/stable/installation/
Try to install python3.9 as suggested by the terminal.
I am using ubuntu 18. The default python3 version is 3.6. I updated to 3.7 today and update the alternatives to point to python3.7.
I can use python3.7 by typing python3. I can also use pip3 --version (20.0.2).
I can activate the virtual environment by using pipenv shell. But I cannot install package using pipenv install . It gives me the following error:
pipenv.exceptions.InstallError]: ['Traceback (most recent call last):', ' File "/home/johnchan/.local/share/virtualenvs/src-lkQYyAWf/bin/pip", line 5, in <module>', ' from p
ip._internal.cli.main import main', "ModuleNotFoundError: No module named 'pip'"]
ERROR: ERROR: Package installation failed...
Running which pip3: /usr/local/bin/pip3
Running which pipenv: /usr/local/bin/pipenv
Type pip3 inside pipenv gives:
Traceback (most recent call last):
File "/home/johnchan/.local/share/virtualenvs/src-lkQYyAWf/bin/pip3", line 5, in <module>
from pip._internal.cli.main import main
ModuleNotFoundError: No module named 'pip'
python2 -m pip install --user --upgrade pip
python3 -m pip install --user --upgrade pip
After upgrading pip (or pip3, in this case) if the following occurs:
$ ~ pip3 -V
Traceback (most recent call last):
File "/usr/local/bin/pip", line 7, in <module>
from pip._internal import main
ModuleNotFoundError: No module named 'pip._internal'
Force a reinstall of pip:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py --force-reinstall
Verify install:
$ ~ pip3 -V
pip 10.0.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
Now pip3 install <package> and pip3 install --user <package> (for user-level installs) will work correctly.
There should never, ever be any reason you need to run pip in elevated mode.
(note: For Python 2.7, just replace python for python3, and pip for pip3)
Had the same issue on macOS as well, it's a common issue across platforms.
I found the answer here:
Setting up a virtualenv: No module named 'pip'
Seems like it is a bug.
I install pipenv using --re flag which is equivalent to virtualenv venv --no-setuptools.
Then I run python get-pip.py inside pipenv.
It works. I can install package now.
But I don't know the reason why...
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'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
Hello I've installed a local version of pip using
python get-pip.py --user
After that I can't find the path of pip, so I run:
python -m pip install --user Cython
Finally I can't import Cython
import Cython
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'Cython'
Use virtualenv, it is used to create isolated python environments (check this quick guide http://docs.python-guide.org/en/latest/dev/virtualenvs/ )
python -m pip install --user Cython
should probabably be
pip install --user cython