Trouble with pip package manager on CentOS - python

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

Related

Python: pip in venv doesn't install packages in the venv. It install packages in the default location instead. What could be wrong?

Creation of venv with python3 is ok.
However, when I run pip install requests in the venv, the package has been installed in the normal python site-package outside of the venv.framework folder. The pip doesn't install package in the venv.
I've installed python3 from brew.
I've installed python3.9 and python3.10, which are downloaded from the python homepage.
Outside of the venv, the 'which' command looks like this.
which python
/usr/local/bin/python
which python3
/Library/Frameworks/Python.framework/Versions/3.9/bin/python3
which python3.9
/Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9
which python3.10
/Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10
which pip
pip: aliased to /usr/local/bin/pip3
which pip3
/Library/Frameworks/Python.framework/Versions/3.9/bin/pip3
which pip3.9
/Library/Frameworks/Python.framework/Versions/3.9/bin/pip3.9
which pip3.10
/Library/Frameworks/Python.framework/Versions/3.10/bin/pip3.10
echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Inside of the venv:
which python
/....../venv_test/venv/bin/python.
which python3
/....../venv_test/venv/bin/python3
which python3.9
/....../venv_test/venv/bin/python3.9
which python3.10
/....../venv_test/venv/bin/python
which pip
pip: aliased to /usr/local/bin/pip3
which pip3
/....../venv_test/venv/bin/pip3
which pip3.9
/....../venv_test/venv/bin/pip3.9
which pip3.10
/....../venv_test/venv/bin/pip3.10
echo $PATH
/....../venv_test/venv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Please help.

ModuleNotFoundError: No module named 'pip._internal.cli'

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

Pip does not install in USER_SITE

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'

How to fix ModuleNotFoundError: No module named 'pip._internal' with python source code installation [duplicate]

This question already has answers here:
pip: no module named _internal
(30 answers)
Closed last month.
I have installed python3.7 on redhat machine by compiling source code but I have a problem when dealing with pip3. I have made this steps after installation:
sudo ln /usr/local/bin/python3.7 /usr/bin/python3
sudo ln /usr/local/bin/pip3.7 /usr/bin/pip3
python3 -- version gives Python 3.7.3
But I have this errors by running these commands :
python3 -m pip install requests
gives /usr/bin/python3: No module named pip.__main__; 'pip' is a package and cannot be directly executed
pip3 install requests
gives ModuleNotFoundError: No module named 'pip._internal'
Try to reinstall the pip as follows :
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py --force-reinstall
I have had the same issue, eventually found out the I have a version of pip install in C:\Program Files (x86)\Microsoft Visual Studio\Shared\anaconda and it was defaulting to this.
I identified this by using
python -m ensurepip --default-pip
In a command prompt.
Deleted the anaconda folder and it finally works!
If you are on a Unix distribution update pip with sudo:
sudo python3 -m pip install --upgrade pip
To update pip, run:
python -m pip install --upgrade pip

How to install a module to one of many pythons in Fedora 20

I have on my Fedora 20 additionally to 2.7 a python3.6 version installed.
When I run a script with the 3.6 version it's missing the requests module.
When I try to install it with the pip command it says it's already there.
So, how can I install this module in python3.6?
Any hints?
Thanks
Check if pip36 or more likely pip3 is a function you can run. Often times the pip command corresponds to the first installed python version, so if you install one later it gets the suffix according to its version. If that is the case then you'll want to do pip36 (pip3) install moduleXYZ.
Quick and dirty answer is
For python2,x install any package using pip install requests
For python 3.x install any package using pip3 install requests
If you get error during pip3 please run sudo dnf install python3-pip
But the right way is to do it using Virtual Environment in fedona
For py3.4+
$ python3.5 -m venv env # create the virtualenv
$ . env/bin/activate # activate it
(env)$ python -m pip install requests # install a package with pip
For py2.x, 3.x
$ dnf install python-virtualenv # install the necessary tool
$ virtualenv --python /usr/bin/python2.7 env # create the virtualenv
Running virtualenv with interpreter /usr/bin/python2.7
New python executable in env/bin/python2.7
Also creating executable in env/bin/python
Installing setuptools, pip...done.
$ . env/bin/activate # activate it
(env)$ python -m pip install requests # install a package with pip
Refrence

Categories

Resources