I have import psycopg2 in my code yet I keep getting ImportError: No module named psycopg2when I try to run it. I've tried
└─$ pip3 install psycopg2
└─$ pip install psycopg2-binary
└─$ sudo apt-get install build-dep python-psycopg2
anyone have a solution to this?
The issue here is: Which Python version do you want to have psycopg2? I am posting 2 solutions, since I'm not sure which one is helpful in your case:
If you want to install it for Python 2, python -m pip install psycopg2 should do this.
If you want to install the package for Python 3, you can run python3 -m pip or pip3. This should avoid confusions with Python 2 installations.
Related
At first, I was trying to install evo (a package for SLAM research) from source and I encountered an error:
ModuleNotFoundError: No module named 'numpy'
So then I tried to install numpy using pip install numpy. However I encountered another error:
SystemError: Cannot compile 'Python.h'. Perhaps you need to install python-dev|python-devel.
Finally, I tried to install python-dev using sudo apt-get install python-dev, and I found out it has been installed already. So I don't know where the problem is.
My default python version is 3.8.16
Could anyone help me with this issue?
maybe conda could install it?
conda install -c anaconda numpy
it isn't generally ideal to mix conda and pip, but it should still install numpy successfully.
Run pip3 install --upgrade pip and try again.
If it doesn't work, try sudo apt-get install pypy-dev instead of python-dev.
You can also try sudo apt-get install python3-numpy
pip used to work fine until recently. First I was trying to install a pip-package using
pip install -e [some-git-link]
and I get the error
Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: '/home/me/.local/lib/python2.7/site-packages/pip-19.0.1.dist-info/METADATA'
I then cd'ed into site-packages and the folder is empty. Indeed, I have pip installed in dis-packages and its version is 18.1, not 19.0!
I tried to update pip through
pip install -U pip
but I get the same error.
Typing
pip --version
I get
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/init.py:83: RequestsDependencyWarning: Old version of cryptography ([1, 2, 3]) may cause slowdown.
warnings.warn(warning, RequestsDependencyWarning)
pip 18.1 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)
so it seems that pip 18.1 is installed. Indeed, if I try
sudo apt-get install python-pip
I get
python-pip is already the newest version (8.1.1-2ubuntu0.4).
0 upgraded, 0 newly installed, 0 to remove and 62 not upgraded.
I was wondering if all these problems were coming from the warning on the cryptography, and so I tried to do
sudo pip install --upgrade cryptography
but obviously I go back to the same Environment Error.
Thou shalt not use sudo with pip. Using sudo with pip is asking for trouble. When you do that you are having pip and your OS's package manager get into a fight. When they fight no one wins, least of all your Python installation and personal sanity. I know countless tutorials tell you to sudo pip install, but they are not your friends. The only safe and reliable way to maintain a functional Python installation is to let your OS's package manager manage what it wants to manage and either use pip install --user or virtual environments (using either virtualenv or optionally python -m venv if you're on Python 3).
I really can't stress enough that you will constantly be running into little weird things (and occasional catastrophic problems) within your Python installation if you persistently sudo install things. Learn to love virtual environments! You can even modify your shell's PATH so that things you install in an environment are available as commands (which is commonly why people think they need sudo pip install).
You could test to update PythonOpenSSL :
$ sudo python -m easy_install --upgrade pyOpenSSL
If not Ok, please do :
$ sudo pip install --upgrade cryptography
But error with : $ sudo pip
So do after :
$ sudo python -m easy_install --upgrade pyOpenSSL
Have Fun,
Johan MRe
I was getting this error trying to install packages while building a Docker image (with python:3.8 as base). Upgrading pyOpenSSL as #Johan MRe suggested solved it for me.
RUN python3 -m easy_install --upgrade pyOpenSSL
How to deal with "Could not install packages due to an EnvironmentError" when upgrade pip
First run command line in Administration mode both window and OS:
Next,
For windows: use this command to upgrade pip
python -m pip install --user --upgrade pip
For MacOS:
sudo python -m pip install --user --upgrade pip
I am trying to install paho-mqtt package for my python project. But it gives the error
Error: Python packaging tool 'pip' not found.
I am using ubuntu 16.04 and I am running this command
pip install paho-mqtt
Can anyone tell me is there another way to install this?
Install pip first, if using python2
sudo apt-get install python-pip
or for python3
sudo apt-get install python3-pip
Python uses pip to install various Python modules like request, jsonpickel etc.
So you need to install pip first as said by #Asoul
I've already installed the dependencies with sudo apt-get build-dep python-psycopg2 and then installing psycopg2 with sudo pip install psycopg2 and even with easy_install psycopg2. But even after all this, if I run python3 code.py I get
ImportError: No module named 'psycopg2'
If I run sudo apt-get build-dep python3-psycopg2 I get
Picking 'psycopg2' as source package instead of 'python3-psycopg2'
0 upgraded, 0 newly installed, 0 to remove and 144 not upgraded.
Same with sudo apt-get build-dep python-psycopg2
Please help.
its always better to work in virtualenv and not mess up with your system
try:
virtualenv -p /usr/bin/python3 test_env
source test_env/bin/activate
pip install psycopg2
run python and try to import
if you insist on installing it on your systems python try:
pip3 install psycopg2
If you are using the Anaconda distribution, make sure to go with:
conda install -c anaconda psycopg2=2.6.2
https://anaconda.org/anaconda/psycopg2
try:
# debian like
$ sudo apt-get install python3-dev
$ pip3 install psycopg2
# check installation
$ python3
import psycopg2
I faced the same issue. I tried
'sudo apt-get build-dep python-psycopg2'
It didn't work.
I was trying to connect to a postgres database. It turns out that I didn't have postgresql installed. Once I installed it, the error went away.
In my case, pip3 install psycopg2 made psycopg3 available for python3, while I was trying to execute my code in python 2.7 by default
so changing my call from
python foo.py to python3 foo.py helped
I know that in order to install a package I need to execute:
sudo pip install package_name
But how can I know what is the name of package - I should give as an argument.
I found in pypi a package I want to install - pcapy:
https://pypi.python.org/pypi/pcapy/0.10.3
I tried:
sudo pip install pcapy
It didn't work...
What is the right way to install this package?
Thank you very much!
That package isn't in the PyPI. There's a page, but the source code is hosted elsewhere for some reason (this is the first time I've seen it):
Ubuntu has a (probably old) package:
$ sudo apt-get install python-pcapy
You can also build it from source:
$ sudo pip install "http://corelabs.coresecurity.com/index.php?module=Wiki&action=attachment&type=tool&page=Pcapy&file=pcapy-0.10.8.tar.gz"