Cannot import package that I just installed - python

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.*.

Related

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'

Trouble with pip package manager on CentOS

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

python virtual env somehow using wrong pip

strugging to get pip install working with virtualenv.
$ virtualenv env
$ source env/Scripts/activate
I now have two python installations:
(env) $ where python
D:\my_folder\env\Scripts\python.exe
C:\Users\Me\Anaconda3\python.exe
I am using the one I want:
(env) $ which python
D:\my_folder\env\Scripts\python.exe
Same with pip:
(env) $ where pip
D:\my_folder\env\Scripts\pip.exe
C:\Users\Me\Anaconda3\Scripts\pip.exe
(env) $ which pip
D:\my_folder\env\Scripts\pip.exe
However I have the following
(env) $ pip -V
pip 18.0 from C:\Users\Me\Anaconda3\Lib\site-packages\pip (python 3.6)
wrong place!
(env) $ pip freeze
... dumps out my global packages!!
(env) $ pip install requirements.txt
... fails because requirements cannot be met.
I have a feeling that I have bad environment variable somewhere but don't really know where to look?! I'm just coming over from node and npm and finding python modules to be a bit of a car crash (although the language is awesome). Anyhow all help appreciated.
(EDIT)
OK, so (thanks to #alec_djinn) the following works:
python -m pip install requirements.txt
however
python -m pip freeze
still dumps my global installations.

How can I install a package with setup.py provided, within a virtualenv?

I have goose installed system-wide, but not in a virtualenv I have been working on
$ python -c "import goose" #ok
(venv)$ python -c "import goose" #not ok
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named goose
The setup instructions say
mkvirtualenv --no-site-packages goose
git clone https://github.com/grangier/python-goose.git
cd python-goose
pip install -r requirements.txt
python setup.py install
How can I install it within my existing virtualenv venv?
mkvirtualenv goose_project
workon goose_project
git clone https://github.com/grangier/python-goose
cd python-goose/
python setup.py install
and to verify installation
pip freeze | grep "goose"
goose-extractor==1.0.22
Follow the setup instructions, but activate your virtualenv (workon venv or . venv/bin/activate) before calling pip or python.

Categories

Resources