my specific problem is with pip 9.0.3 (no other version tested) on linux.
When I try to install a package for locally for my linux user using
$ pip3 install --user numpy
...
Successfully installed numpy-1.18.1
I get
$ python3 -m numpy
/usr/bin/python3: No module named numpy
As far as I know, pip3 should install in
$ python3 -m site
...
USER_BASE: '/home/username/.local' (exists)
USER_SITE: '/home/username/.local/lib/python3.6/site-packages' (exists)
ENABLE_USER_SITE: True
but the directory is empty.
But what I've found are modules in /home/username/.username/modules which seems to be installed by pip3.
How can I configure pip to use the correct USER_SITE?
Q: Which pip/python is used?
$ which pip3
/usr/bin/pip3
$ pip3 --version
pip 9.0.3 from /usr/lib/python3.6/site-packages (python 3.6)
$ python3 --version
Python 3.6.8
Q: how does sys.path looks like?
$ python3
>>> import sys
>>> sys.path
['', '/usr/lib64/python36.zip', '/usr/lib64/python3.6', '/usr/lib64/python3.6/lib-dynload', '/home/username/.local/lib/python3.6/site-packages', '/usr/lib64/python3.6/site-packages', '/usr/lib/python3.6/site-packages']
Q: Have you tried to upgrade your pip first?
I have no super-user privileges on this machine (why I try to install in USER_SITE).
Q: Do you have local configuration files like here?
The online doc describes pip 20.0.2 instead of 9.0.3 or similar.
However, there are no such config files like
/home/username/.config/pip/pip.conf
/home/username/.pip/pip.conf
/etc/pip.conf
/etc/xdg/pip/pip.conf
Q: have you tried to install/upgrade in USER_SITE?
Yes. But without the correct path, it will not work.
$ python3 -m pip install -U --user pip
...
Successfully installed pip-20.0.2
$ which pip
~/.username/scripts/pip
$ pip --version
Traceback (most recent call last):
File "/home/username/.username/scripts/pip", line 7, in <module>
from pip._internal.cli.main import main
ModuleNotFoundError: No module named 'pip._internal'
Related
Need some help here.
I have two versions of pip and pip3 installed in different location.
When I try to do a pip install package-name it throws Error as:
ModuleNotFoundError: No module named 'pip._internal.cli'
pip 18.1 from /project/miniconda/lib/python3.7/site-packages/pip (python 3.7)
$ which pip
/project/miniconda/bin/pip
$ which pip3
/usr/local/bin/pip3
$ pip -V
pip 18.1 from /project/miniconda/lib/python3.7/site-packages/pip (python 3.7)
$ pip3 -V
Traceback (most recent call last):
File "/usr/local/bin/pip3", line 7, in <module>
from pip._internal.cli.main import main
ModuleNotFoundError: No module named 'pip._internal.cli'```
Since I don't have super user access, I cannot modify pip._internal.cli.main to pip.internal.cli.main.
Please help.
Please upgrade pip with python -m pip install --upgrade --force-reinstall pip.
You can try to install any package with: python -m pip install package-name for python2.7 and python3 -m pip install package-name for python3.
Using python -m pip install instead of just pip install is recommended. The reason is that it will use the correct interpreter for your python installation, specially if you have many versions installed. More details here: https://snarky.ca/why-you-should-use-python-m-pip/
Try this it worked for me
python3 -m pip install --user --upgrade pip
Image Link for code
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...
Would like to install python packages (specifically psycopg2) using pip on CentOS. Cannot understand with what's wrong with my python3 installation, pipnot recognized:
$pip install psycopg2
-bash: /usr/bin/pip: /usr/bin/python: bad interpreter: No such file or directory
$pip install --upgrade pip
-bash: /usr/bin/pip: /usr/bin/python: bad interpreter: No such file or directory
$ python3.7 -V
Python 3.7.2
$which python3.7
/usr/local/bin/python3.7
Any idea why pip cannot work?
You can invoke the pip module from your preferred Python interpreter by running:
python3.7 -m pip install psycopg2
I created a virtual environment, installed pandas, and tried to import it:
$ pip install pandas ...
...
Installing collected packages: numpy, pandas...
$ find $VIRTUAL_ENV -name pandas
/home/sds/.virtualenvs/myenv/lib64/python3.6/dist-packages/pandas
$ python -c 'import pandas'
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'pandas'
$ python --version
Python 3.6.5
$ pip --version
pip 10.0.1 from /home/sds/.virtualenvs/myenv/local/lib/python3.6/dist-packages/pip (python 3.6)
$ wh python
python is /home/sds/.virtualenvs/myenv/bin/python
$ wh pip
pip is /home/sds/.virtualenvs/myenv/bin/pip
One weirdness I noticed is:
$ ls /home/sds/.virtualenvs/myenv/lib*/python3.6/site-packages/
/home/sds/.virtualenvs/myenv/lib/python3.6/site-packages/:
total 0
/home/sds/.virtualenvs/myenv/lib64/python3.6/site-packages/:
total 0
what am I doing wrong?
The "workaround" is:
cd $VIRTUAL_ENV/myenv
for d in lib lib64; do
cd $d/python3.6
rmdir -v site-packages && mv -v dist-packages site-packages
cd ../..
done
obviously, something is wrong...
PS. virtualenv setup:
pip3 install --user virtualenv virtualenvwrapper
pip3 install --user --upgrade virtualenv virtualenvwrapper
mkvirtualenv -p python3 myenv
I just can guess which system you are using. I figured out that on mac I have to use pip3 install ... for packages I want to use with python 3.6.*.
I installed pip through brew, and I can't get it to use python 3 instead of 2.7. Here's the information I think might be relevant to demonstrate what's happening.
$ pip -V
pip 9.0.1 from /Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg (python 2.7)
$ pip2 -V
pip 9.0.1 from /Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg (python 2.7)
$ pip3 -V
-bash: pip3: command not found
$ which pip
/usr/local/bin/pip
$ sudo python3 get-pip.py
The directory '/Users/tj/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/tj/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already up-to-date: pip in /usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages
$ sudo easy_install3 pip
sudo: easy_install3: command not found
$ sudo easy_install-3.6 pip
sudo: easy_install-3.6: command not found
$ sudo easy_install pip
Searching for pip
Best match: pip 9.0.1
Processing pip-9.0.1-py2.7.egg
pip 9.0.1 is already the active version in easy-install.pth
Installing pip script to /usr/local/bin
Installing pip2.7 script to /usr/local/bin
Installing pip2 script to /usr/local/bin
Using /Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg
Processing dependencies for pip
Finished processing dependencies for pip
I tried everything I could find online with no luck. The main symptom of this problem is when I use pip to install a package, it always goes into 2.7 (or fails to install because numpy is deprecated or something like that).
On OSX, brew (or other) python 2.7/3 is installed separately to the older version of 2.7 that comes with OSX. Trust me when I say you DO NOT WANT TO MESS WITH IT.
Try typing pip3
$ pip3 --version
$ pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6)
Whereas pip (for 2.7) is not even installed.,
$ pip --version
$ zsh: command not found: pip
Even if you try:
$ brew install pip
Leads to
If you meant "pip" specifically:
Homebrew provides pip via: `brew install python`. However you will then
have two Pythons installed on your Mac, so alternatively you can install
pip via the instructions at:
https://pip.readthedocs.io/en/stable/installing/
AS A LAST RESORT:
python3 -m ensurepip
will ensure/fix a system has it.
pip3 should be located at /usr/local/bin/pip3
Contents are:
#!/usr/local/opt/python3/bin/python3.6
# EASY-INSTALL-ENTRY-SCRIPT: 'pip==9.0.1','console_scripts','pip3'
__requires__ = 'pip==9.0.1'
import re
import sys
from pkg_resources import load_entry_point
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(
load_entry_point('pip==9.0.1', 'console_scripts', 'pip3')()
)