I'm attempting to make a website with a few others for the first time, and have run into a weird error when trying to use Django/Python/VirtualEnv. I've found solutions to this problem for other operating systems, such as Ubuntu, but can't find any good solutions for Mac.
This is the relevant code being run:
virtualenv -p python3 venv
source venv/bin/activate
pip install -r requirements.txt
After running that block, I get the following errors:
AssertionError
Failed building wheel for django-toolbelt
Running setup.py bdist_wheel for psycopg2
...
AssertionError
Failed building wheel for psycopg2
Failed to build django-toolbelt psycopg2
I believe I've installed the "django-toolbelt" and "psycopg2", so I'm not sure why it would be failing.
The only difference I can think of is that I did not use the command
sudo apt-get install libpq-dev
as was instructed for Ubuntu usage as I believe that installing postgresql with brew took care of the header.
Thanks for any help or insight!
For MacOS users
After trying all the above methods (which did not work for me on MacOS 10.14), that one worked :
Install openssl with brew install openssl if you don't have it already.
add openssl path to LIBRARY_PATH :
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
install psycopg2 with pip pip3 install psycopg2
I had the same problem on Arch linux. I think that it's not an OS dependant problem. Anyway, I fixed this by finding the outdated packages and updating then.
pip uninstall psycopg2
pip list --outdated
pip install --upgrade wheel
pip install --upgrade setuptools
pip install psycopg2
I was also getting same error.
Using Python 3.7.3 and pip 19.1.1.
I used following command.
pip install psycopg2-binary==2.8.3
TDLR
If you aren't used to installing Python C-extensions, and psycopg2 isn't a core part of your work, try
pip install psycopg2-binary
Building Locally
psycopg2 is a C-extension, so it requires compilation when being installed by pip. The Build Prerequisites section of the docs explain what must be done to make installation via pip possible. In summary (for psycopg 2.8.5):
a C compiler must be installed on the machine
the Python header files must be installed
the libpq header files must be installed
the pg_config program must be installed (it usually comes with the libpq headers) and on $PATH.
With these prerequisites satisfied, pip install psycopg2 ought to succeed.
Installing pre-compiled wheels
Alternatively, pip can install pre-compiled binaries so that compilation (and the associated setup) is not required. They can be installed like this:
pip install psycopg2-binary
The docs note that
The psycopg2-binary package is meant for beginners to start playing with Python and PostgreSQL without the need to meet the build requirements.
but I would suggest that psycopg2-binary is often good enough for local development work if you are not using psycopg2 directly, but just as a dependency.
Concluding advice
Read the informative installation documentation, not only to overcome installation issues but also to understand the impact of using the pre-compiled binaries in some scenarios.
I had same problem and this appears to be a Mojave Issue, I was able to resolve with:
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
For Mac OS X users:
1. First check your postgresql path by running this command in terminal:
pg_config
If this fails lookup how to add pg_config to your path.
2. Next install Xcode Tools by running this command in terminal:
xcode-select --install
If you have both those sorted out now try to install psycopg2 again
For MacOS users, this question has the correct solution:
install command line tools if necessary:
xcode-select --install
then
env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip install psycopg2
I was also facing the same after running all the above commands, but the following two commands worked for me:
Instead of pip, use this:
sudo apt-get install libpq-dev
then run this command:
pip install psycopg2
On OS X, I was able to solve this by simply upgrading wheel before installing psycopg2:
pip install --upgrade wheel
For OSX Sierra users, it seems that an xcode update is the solution: Can't install psycopg2 package through pip install... Is this because of Sierra?
I tried all the above solutions but they did not work for me. What I did was change the psycopg2 version in my requirements.txt file from psycopg2==2.7.4 to psycopg2==2.7.6
Is your error message complete? the most encountered reason for failing to install psycopg2 on mac from pip is pg_config is not in path.
by the way, using macports or fink to install psycopg2 is more recommended way, so you don't have to worry about pg_config, libpq-dev and python-dev.
plus, are using Python 3.5? then upgrage your wheel to > 0.25.0 using pip.
I faced the same issue, but the answers above didn't work for me.
So this is what I did in my requirements.txt
psycopg2-binary==2.7.6.1 and it worked fine
I had this issue on several packages, including psycopg2, numpy, and pandas. I simply removed the version from the requirements.txt file, and it worked.
So instead of psycopg2-binary==2.7.6.1 I just had psycopg2-binary.
I know you are asking for development environment but if you are deploying on server say, Heroku. Just add below line in the requirements.txt of your project.
django-heroku==0.3.1
As this package itself will install the required packages like psycopg2 on server deployment.So let the server(heroku) should take care of it.
sudo apt install libpq-dev python3.X-dev
where X is the sub version,
these should be followed by :
pip install --upgrade wheel
pip install --upgrade setuptools
pip install psycopg2
Enjoy !!!
I solved my problem by updating/installing vs_BuildTools. The link to the software was given in the error itself.
Error Image
Fixed by installing python3.7-dev: sudo apt install python3.7-dev, based on the link.
Python: 3.7
Ubuntu: 20.04.3 LTS
Related
I have Python 2.6 in my Linux rhel-5. I have installed pip and required CFFI packages. When I try to run a sample CFFI program:
ffi = FFI()
it says:
File "/usr/lib/python2.6/site-packages/cffi/api.py", line 56, in __init__
import _cffi_backend as backend
ImportError: No module named _cffi_backend
What could be the possible error? Did I miss something during installation? I have installed pip, wheel, pycparser, pytest and cffi.
For python2.x use following command:
python -m pip install cffi
for python3.x
python3 -m pip install cffi
I needed to uninstall and install it again:
sudo pip uninstall cryptography
sudo pip uninstall paramiko
then install pagamiko again
sudo pip install paramiko
and it start to work for me
I recently had the same issue and none of the above solutions worked for me.
Here is what worked.
sudo apt remove python3-cffi
sudo python3 -m pip install cffi
Did you compile Python from source, and if so, did it give you any errors during the configure/make/make install phase? Compiling Python from source can be a real beast on older Red Hat systems, so if you installed that way, I'd suggest combing through the configure and make output to be sure that no modules were left out.
In order to get pip install cffi to succeed with no errors, I had to install gcc and libffi-devel from the EL5 repos. From there, I was able to instantiate an FFI instance with no problems:
>>> from cffi import FFI
>>> ffi = FFI()
>>>
Here's the output of pip freeze, for reference:
[root#machine ~]# pip freeze
argparse==1.2.1
autobahn==0.8.10
cffi==1.5.2
characteristic==14.3.0
pika==0.9.13
pyasn1==0.1.7
pyasn1-modules==0.0.8
pycparser==2.14
pycrypto==2.6.1
pyOpenSSL==0.12
pysnmp==4.2.5
requests==2.7.0
service-identity==14.0.0
six==1.7.3
Twisted==14.0.0
version-utils==0.2.2
wheel==0.24.0
zope.interface==4.1.1
If you've got the same or better versions of the relevant packages installed, I'd try a pip -vvv install --upgrade --force-reinstall cffi, just to see if there are perhaps errors that pip was masking, and go from there.
I had the same problem, following this thread https://github.com/pyca/cryptography/issues/4403, I solved the problem by reinstalling and upgrading with the command:
pip install -U cffi
You have to first remove the following packages:
cryptography
bcrypt
paramiko
Now use the following command to install:
pip -vvv install --upgrade --force-reinstall cffi
Have the same problem. After many attempts adding import cffi solve the issue.
Make sure you have cffi and cryptography installed.
You could look at the code L56 in /usr/lib/python2.6/site-packages/cffi/api.py
It needs the _cffi_backend.so in your pythonpath. You could install the python-cffi for it. But not sure whether it is in your RPM repo, especially you are using RHEL-5.
Here is an RPM for CENTOS http://cbs.centos.org/koji/rpminfo?rpmID=20613
Hope it helps. I am still searching the source code for building the _cffi_backend.so.
For me there was no way to install cffi on python3.8 because of this:
ImportError: cannot import name 'sysconfig' from 'distutils' (/usr/lib/python3.8/distutils/__init__.py)
Somehow, the package python3-distutils does not exist in Ubuntu 16.04.
So I ended up installing python3.7 and now I finally could install cffi, fixing the problem mentioned by the TS.
You should install cffi via pip install cffi
to get the latest version. I had to restart my application for it to recognize the cffi installation.
I was getting this error while trying to get the cryptography module to work with Python 3.8 for AWS Lambda.
Adding the cffi*manylinux*.whl files to my Lambda Layer (as suggested here) worked.
The cffi module comes built in for many python distributions, but not on AWS Lambda
For AWS Lambda I was facing the same issue when running on Python3.7. When I downgraded it to Python3.6, this issue was resolved.
I think this packaged might have been present in Python3.6 version and later was removed. Adding this package while making layers for AWS Lambda might resolve the problem for Python3.7.
I encountered this issue when trying to install packages in a local directory using pip install -t . and then running python (2.7). My solution was to remove the -t and not install into a local directory.
it worked after adding " import cffi " in my application.
please refer for more details.
https://buildmedia.readthedocs.org/media/pdf/cffi/latest/cffi.pdf
Thanks to #MPlanchard, for his answer which helped identify the cause
In my case, the issue was related to python3.9, changing to python3.8 it just works well!
After many futile efforts to install the right packages, the right python versions and building the perfect layer, resorting to installing Fabric solved it for me
I got this issue running an Ansible playbook using python 3.9 under Ubuntu-18.04 in WSL2. It was sorted by doing:
sudo apt-get remove -y python3-cffi-backend
sudo apt-get install -y python3-cffi-backend
I'm trying to install psycopg2-binary on Mac OS Catalina and Python 3.8. The build fails always when try to install using pip3. Is there any solution for this in Catalina ?
"ERROR: Failed building wheel for psycopg2-binary"
I was able to compile psycopg2 on OS X 10.15.1 Catalina with $VENV/bin/pip install psycopg2 after doing a couple of things, first:
Re-installed xcode command line headers (though it may have just been that I accepted the new terms of service) using xcode-select --install
Linked homebrew ssl headers using export LDFLAGS="-L/usr/local/opt/openssl#1.1/lib" and export CPPFLAGS="-I/usr/local/opt/openssl#1.1/include"
installing with $VENV/bin/pip install psycopg2 where VENV is the directory of my virtual environment
It looks like some others have had successes with just the xcode, but I also needed to add ssl things to the path.
Try ussing the binary version:
pip install psycopg2-binary
If you still have the same issue try using Pipenv instead
and if you still cant install it in pipenv try it with the run command and the binary version:
pipenv run pip install psycopg2-binary
I'm trying to install some packages with pip.
But pip install unroll gives me
Command "python setup.py egg_info" failed with error code 1 in
C:\Users\MARKAN~1\AppData\Local\Temp\pip-build-wa7uco0k\unroll\
How can I solve this?
About the error code
According to the Python documentation:
This module makes available standard errno system symbols. The value of each symbol is the corresponding integer value. The names and descriptions are borrowed from linux/include/errno.h, which should be pretty all-inclusive.
Error code 1 is defined in errno.h and means Operation not permitted.
About your error
Your setuptools do not appear to be installed. Just follow the Installation Instructions from the PyPI website.
If it's already installed, try
pip install --upgrade setuptools
If it's already up to date, check that the module ez_setup is not missing. If it is, then
pip install ez_setup
Then try again
pip install unroll
If it's still not working, maybe pip didn't install/upgrade setup_tools properly so you might want to try
easy_install -U setuptools
And again
pip install unroll
Here's a little guide explaining a little bit how I usually install new packages on Python + Windows. It seems you're using Windows paths, so this answer will stick to that particular SO:
I never use a system-wide Python installation. I only use virtualenvs, and usually I try to have the latest version of 2.x & 3.x.
My first attempt is always doing pip install package_i_want in some of my Visual Studio command prompts. What Visual Studio command prompt? Well, ideally the Visual Studio which matches the one which was used to build Python. For instance, let's say your Python installation says Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec 5 2015, 20:40:30) [MSC v.1500 64 bit (AMD64)] on win32. The version of Visual Studio used to compile Python can be found here, so v1500 means I'd be using vs2008 x64 command prompt
If the previous step failed for some reason I just try using easy_install package_i_want
If the previous step failed for some reason I go to gohlke website and I check whether my package is available over there. If it's so, I'm lucky, I just download it into my virtualenv and then I just go to that location using a command prompt and I do pip install package_i_want.whl
If the previous step didn't succeed I'll just try to build the wheel myself and once it's generated I'll try to install it with pip install package_i_want.whl
Now, if we focus in your specific problem, where you're having a hard time installing the unroll package. It seems the fastest way to install it is doing something like this:
git clone https://github.com/Zulko/unroll
cd unroll && python setup.py bdist_wheel
Copy the generated unroll-0.1.0-py2-none-any.whl file from the created dist folder into your virtualenv.
pip install unroll-0.1.0-py2-none-any.whl
That way it will install without any problems. To check it really works, just login into the Python installation and try import unroll, it shouldn't complain.
One last note: This method works almost 99% of the time, and sometimes you'll find some pip packages which are specific to Unix or Mac OS X, in that case, when that happens I'm afraid the best way to get a Windows version is either posting some issues to the main developers or having some fun by yourself porting to Windows (typically a few hours if you're not lucky) :)
It was resolved after upgrading pip:
python -m pip install --upgrade pip
pip install "package-name"
I got stuck exactly with the same error with psycopg2. It looks like I skipped a few steps while installing Python and related packages.
sudo apt-get install python-dev libpq-dev
Go to your virtual env
pip install psycopg2
(In your case you need to replace psycopg2 with the package you have an issue with.)
It worked seamlessly.
I got this same error while installing mitmproxy using pip3. The below command fixed this:
pip3 install --upgrade setuptools
Download and install the Microsoft Visual C++ Compiler for Python 2.7 from https://www.microsoft.com/en-in/download/details.aspx?id=44266 - this package contains the compiler and set of system headers necessary for producing binary wheels for Python 2.7 packages.
Open a command prompt in elevated mode (run as administrator)
Firstly do pip install ez_setup
Then do pip install unroll (It will start installing numpy, music21, decorator, imageio, tqdm, moviepy, unroll) # Please be patient for music21 installation
Python 2.7.11 64 bit used
Other way:
sudo apt-get install python-psycopg2 python-mysqldb
I had the same issue when installing the "Twisted" library and solved it by running the following command on Ubuntu 16.04 (Xenial Xerus):
sudo apt-get install python-setuptools python-dev build-essential
It's a dependency issue.
I tried running the following commands helped me sorting out the dependencies, in my case the dependency was
grpcio
pip3 install --upgrade pip
python3 -m pip install --upgrade setuptools
pip3 install --no-cache-dir --force-reinstall -Iv grpcio==1.36.1
pip3 install pulsar-client==2.7.0
remember you must have python3 installed in your system.
First try:
pip install unroll
For sure not work :)
Then Try:
pip2 install unroll
Still get error Try:
pip3 install unroll
If pip3 Worked then suggest to change configuration to use pip3 as pip because you will get a lot of issues as the modern now is Python3 = pip3 if you execute a script files.
I had the same problem.
The problem was:
pyparsing 2.2 was already installed and my requirements.txt was trying to install pyparsing 2.0.1 which throw this error
Context: I was using virtualenv, and it seems the 2.2 came from my global OS Python site-packages, but even with --no-site-packages flag (now by default in last virtualenv) the 2.2 was still present. Surely because I installed Python from their website and it added Python libraries to my $PATH.
Maybe a pip install --ignore-installed would have worked.
Solution: as I needed to move forwards, I just removed the pyparsing==2.0.1 from my requirements.txt.
I ran into the same error code when trying to install a Python module with pip.
#Hackndo noted that the documentation indicate a security issue.
Based on that answer, my problem was solved by running the pip install command with sudo prefixed:
sudo pip install python-mpd2
For me this worked
python3 -m pip3 install -U pip
you can also try
python -m pip install -U pip
pip3 install --upgrade setuptools
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with -m pip instead of running pip directly.
Use python3 -m pip "command", eg:
python3 -m pip install --user pyqt5
I tried all of the above with no success. I then updated my Python version from 2.7.10 to 2.7.13, and it resolved the problems that I was experiencing.
That means some packages in pip are old or not correctly installed.
Try checking version and then upgrading pip.Use auto remove if that works.
If the pip command shows an error all the time for any command or it freezes, etc.
The best solution is to uninstall it or remove it completely.
Install a fresh pip and then update and upgrade your system.
I have given a solution to installing pip fresh here - python: can't open file get-pip.py error 2] no such file or directory
next installation helps me:
pip3 install cython
This worked for me:
sudo xcodebuild -license
Upgrading Python to version 3 fixed my problem. Nothing else did.
I downloaded the .whl file from http://www.lfd.uci.edu/~gohlke/pythonlibs/ and then did:
pip install scipy-0.19.1-cp27-cp27m-win32.whl
Note that the version you need to use (win32/win_amd-64) depends on the version of Python and not that of Windows.
I had this problem using virtualenvs (with pipenv) on my new development setup.
I could only solve it by upgrading the psycopg2 version from 2.6.2 to 2.7.3.
More information is at https://github.com/psycopg/psycopg2/issues/594
I faced the same problem with the same error message but on Ubuntu 16.04 LTS (Xenial Xerus) instead:
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-w71uo1rg/poster/
I tested all the solutions provided above and none of them worked for me. I read the full TraceBack and found out I had to create the virtual environment with Python version 2.7 instead (the default one uses Python 3.5 instead):
virtualenv --python=/usr/bin/python2.7 my_venv
Once I activated it, I run pip install unirest successfully.
try on linux:
sudo apt install python-pip python-bluez libbluetooth-dev libboost-python-dev libboost-thread-dev libglib2.0-dev bluez bluez-hcidump
Had the same problem on my Win10 PC with different packages and tried everything mentioned so far.
Finally solved it by disabling Comodo Auto-Containment.
Since nobody has mentioned it yet, I hope it helps someone.
I had the same problem and was able to fix by doing the following.
Windows Python needs Visual C++ libraries installed via the SDK to build code, such as via setuptools.extension.Extension or numpy.distutils.core.Extension. For example, building f2py modules in Windows with Python requires Visual C++ SDK as installed above. On Linux and Mac, the C++ libraries are installed with the compiler.
https://www.scivision.co/python-windows-visual-c++-14-required/
Following below command worked for me
[root#sandbox ~]# pip install google-api-python-client==1.6.4
Methods to solve setup.pu egg_info issue when updating setuptools or not other methods doesnot works.
If CONDA version of the library is available to install use conda instead of pip.
Clone the library repo and then try installation by pip install -e . or by python setup.py install
upgrading python's version did the work for me.
I have just encountered the same problem when trying to pip install -e . a new repo. I did not notice that the contents of setup.py haven't been saved properly and I was effectively running the command with an empty setup.py.
Hence you may experience the same error message if the setup.py of the target package is either empty or malformed.
I solved it on Centos 7 by using:
sudo yum install libcurl-devel
I've tried to install psycopg2 (PostgreSQL Database adapater) from this site, but when I try to install after I cd into the package and write
python setup.py install
I get the following error:
Please add the directory containing pg_config to the PATH
or specify the full executable path with the option:
python setup.py build_ext --pg-config /path/to/pg_config build ...
or with the pg_config option in 'setup.cfg'.
I've also tried 'sudo pip install psycopg2' and I got the same message.
After reading through the docs, it asks to look at the setup.cfg file (which is below):
[build_ext]
define=
# PSYCOPG_DISPLAY_SIZE enable display size calculation (a little slower)
# HAVE_PQFREEMEM should be defined on PostgreSQL >= 7.4
# PSYCOPG_DEBUG can be added to enable verbose debug information
# "pg_config" is required to locate PostgreSQL headers and libraries needed to
# build psycopg2. If pg_config is not in the path or is installed under a
# different name uncomment the following option and set it to the pg_config
# full path.
#pg_config=
# Set to 1 to use Python datetime objects for default date/time representation.
use_pydatetime=1
# If the build system does not find the mx.DateTime headers, try
# uncommenting the following line and setting its value to the right path.
#mx_include_dir=
# For Windows only:
# Set to 1 if the PostgreSQL library was built with OpenSSL.
# Required to link in OpenSSL libraries and dependencies.
have_ssl=0
# Statically link against the postgresql client library.
#static_libpq=1
# Add here eventual extra libraries required to link the module.
#libraries=
However, I'm not sure if I'm suppose to edit this file, since the documentation states the following:
then take a look at the setup.cfg file.
Some of the options available in setup.cfg are also available as command line arguments of the build_ext sub-command. For instance you can specify an alternate pg_config version using:
$ python setup.py build_ext --pg-config /path/to/pg_config build
Use python setup.py build_ext --help to get a list of the options supported.
I've gotten the list of options supported but I'm not sure where to go from there
Debian/Ubuntu
Python 2
sudo apt install libpq-dev python-dev
Python 3
sudo apt install libpq-dev python3-dev
Additional
If none of the above solve your issue, try
sudo apt install build-essential
or
sudo apt install postgresql-server-dev-all
With pip
Install the psycopg2-binary PyPI package instead, it has Python wheels for Linux and Mac OS.
pip install psycopg2-binary
I was getting this issue because I hadn't yet installed PostgreSQL on my machine.
For Mac
brew install postgresql
For Mac without brew
python3 -m pip install psycopg2-binary
If you need to install without compiling:
pip install psycopg2-binary
https://www.psycopg.org/docs/install.html#binary-install-from-pypi
Note: The psycopg2-binary package is meant for beginners to start
playing with Python and PostgreSQL without the need to meet the build
requirements. If you are the maintainer of a publish package depending
on psycopg2 you shouldn’t use ‘psycopg2-binary’ as a module
dependency. For production use you are advised to use the source distribution.
If you are on Ubuntu or any other debian-based distro, try
sudo apt-get install python3-psycopg2
Otherwise, you need to find and install the Postgresql client packages for your distribution. psycopg2 installation from source
On Macbook with M1 i had to install postgresql
brew install postgresql
(If you don't have brew: https://brew.sh)
then run the install again
python3 -m pip install psycopg2-binary
Upgrading pip worked for me: pip install --upgrade pip
For OSX with Macports, you can install sudo port install py38-psycopg2 for Python 3.8. You can search for your version of Python with port search psycopg2. At the time of writing, the versions range from 2.7 to 3.9 all up to date with version 2.8.6 of psycopg2.
Note: This probably will not help in a venv.
Edit: So to find your pg_config for a venv, run the command port contents postgresql13 | grep pg_config where postgresql13 is the version of the package of postgresql installed from the above port command. You are looking for a path such as /opt/local/lib/postgresql13/bin/pg_config. Export that to your PATH variable with a command such as export PATH=/opt/local/lib/postgresql13/bin/:$PATH.
Refer to this answer for Homebrew.
On Fedora (tested and built from source on Fedora 35)
pg_config is present in libpq5-devel.
Now try these steps:
sudo dnf install libpq5-devel
python setup.py build
sudo python setup.py install
If you installed Postgres.app on macOS, add its bin directory to the PATH environment variable:
export PATH=/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH
For mac os
install postgresql with : brew install postgresql
then
install psycopg2 with : pip install psycopg2
worked for me
Incase you are using PyCharm/Visual Code Studio terminal, don't do it. Use the default system terminal, as it ensures correct format of brew install is done.
On M1 pro with Intel chip:
brew install postgresql
pip install psycopg2
For me just this worked on Mac:
pip install --upgrade pip
pip install psycopg2-binary
For Mac
I had this issue too. I had followed a guide that had me run
brew install postgresql#15
This worked, but I kept getting the error
Error: pg_config executable not found.
So I then tried to brew install postgres without the #15 after it, and it worked! So, if you have installed postgresql#15 or #any-number, try to brew install without a number.
brew install postgresql
Your error is becouse didn't install the prerequisites on your machine or environment.
You can install prerequisites from here.
In this case probably your missing prerequisite is postgresql you can try below instructors.
For Mac
brew install postgresql
For Linux
sudo apt-get install postgresql
For people building postgres and psycopg2 from source like me, another solution is here:
sudo su
export PATH=/usr/local/pgsql/bin:$PATH #or path to your pg_config
Now setup.py from psycopg2 could find pg_config correctly.
python3 setup.py install
or if you just want to use pip3, pip3 install psycopg2 should work too.
I'm deploying a Django app to a dev server and am hitting this error when I run pip install -r requirements.txt:
Traceback (most recent call last):
File "/var/www/mydir/virtualenvs/dev/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
ImportError: No module named pkg_resources
pkg_resources appears to be distributed with setuptools. Initially I thought this might not be installed to the Python in the virtualenv, so I installed setuptools 2.6 (same version as Python) to the Python site-packages in the virtualenv with the following command:
sh setuptools-0.6c11-py2.6.egg --install-dir /var/www/mydir/virtualenvs/dev/lib/python2.6/site-packages
EDIT: This only happens inside the virtualenv. If I open a console outside the virtualenv then pkg_resources is present, but I am still getting the same error.
Any ideas as to why pkg_resources is not on the path?
July 2018 Update
Most people should now use pip install setuptools (possibly with sudo).
Some may need to (re)install the python-setuptools package via their package manager (apt-get install, yum install, etc.).
This issue can be highly dependent on your OS and dev environment. See the legacy/other answers below if the above isn't working for you.
Explanation
This error message is caused by a missing/broken Python setuptools package. Per Matt M.'s comment and setuptools issue #581, the bootstrap script referred to below is no longer the recommended installation method.
The bootstrap script instructions will remain below, in case it's still helpful to anyone.
Legacy Answer
I encountered the same ImportError today while trying to use pip. Somehow the setuptools package had been deleted in my Python environment.
To fix the issue, run the setup script for setuptools:
wget https://bootstrap.pypa.io/ez_setup.py -O - | python
(or if you don't have wget installed (e.g. OS X), try
curl https://bootstrap.pypa.io/ez_setup.py | python
possibly with sudo prepended.)
If you have any version of distribute, or any setuptools below 0.6, you will have to uninstall it first.*
See Installation Instructions for further details.
* If you already have a working distribute, upgrading it to the "compatibility wrapper" that switches you over to setuptools is easier. But if things are already broken, don't try that.
sudo apt-get install --reinstall python-pkg-resources
fixed it for me in Debian. Seems like uninstalling some .deb packages (twisted set in my case) has broken the path python uses to find packages
I have seen this error while trying to install rhodecode to a virtualenv on ubuntu 13.10. For me the solution was to run
pip install --upgrade setuptools
pip install --upgrade distribute
before I run easy_install rhodecode.
It also happened to me. I think the problem will happen if the requirements.txt contains a "distribute" entry while the virtualenv uses setuptools. Pip will try to patch setuptools to make room for distribute, but unfortunately it will fail half way.
The easy solution is delete your current virtualenv then make a new virtualenv with --distribute argument.
An example if using virtualenvwrapper:
$ deactivate
$ rmvirtualenv yourenv
$ mkvirtualenv yourenv --distribute
$ workon yourenv
$ pip install -r requirements.txt
In CentOS 6 installing the package python-setuptools fixed it.
yum install python-setuptools
After trying several of these answers, then reaching out to a colleague, what worked for me on Ubuntu 16.04 was:
pip install --force-reinstall -U setuptools
pip install --force-reinstall -U pip
In my case, it was only an old version of pillow 3.1.1 that was having trouble (pillow 4.x worked fine), and that's now resolved!
I had this error earlier and the highest rated answer gave me an error trying to download the ez_setup.py file. I found another source so you can run the command:
curl http://peak.telecommunity.com/dist/ez_setup.py | python
I found that I also had to use sudo to get it working, so you may need to run:
sudo curl http://peak.telecommunity.com/dist/ez_setup.py | sudo python
I've also created another location that the script can be downloaded from:
https://gist.github.com/ajtrichards/42e73562a89edb1039f3
Needed a little bit more sudo. Then used easy_install to install pip. Works.
sudo wget https://bootstrap.pypa.io/ez_setup.py -O - | sudo python
sudo easy_install pip
I fixed the error with virtualenv by doing this:
Copied pkg_resources.py from
/Library/Python/2.7/site-packages/setuptools
to
/Library/Python/2.7/site-packages/
This may be a cheap workaround, but it worked for me.
.
If setup tools doesn't exist, you can try installing system-site-packages by typing virtualenv --system-site-packages /DESTINATION DIRECTORY, changing the last part to be the directory you want to install to. pkg_rousources.py will be under that directory in lib/python2.7/site-packages
the simple resoluition is that you can use conda to upgrade setuptools or entire enviroment. (Specially for windows user.)
conda upgrade -c anaconda setuptools
if the setuptools is removed, you need to install setuptools again.
conda install -c anaconda setuptools
if these all methodes doesn't work, you can upgrade conda environement. But I do not recommend that you need to reinstall and uninstall some packages because after that it will exacerbate the situation.
A lot of answers are recommending the following but if you read through the source of that script, you'll realise it's deprecated.
wget https://bootstrap.pypa.io/ez_setup.py -O - | python
If your pip is also broken, this won't work either.
pip install setuptools
I found I had to run the command from Ensure pip, setuptools, and wheel are up to date, to get pip working again.
python -m pip install --upgrade pip setuptools wheel
You can use the command
sudo apt-get install --reinstall python3-pkg-resources
if you are using python3 , this was the case with me.
I ran into this problem after installing the latest Python version 3.10.4.
Somehow, the setuptools package and pip were deleted.
I used the following command to resolve the issue :
in [Windows]
py -m ensurepip --default-pip
For me, this error was being caused because I had a subdirectory called "site"! I don't know if this is a pip bug or not, but I started with:
/some/dir/requirements.txt
/some/dir/site/
pip install -r requirements.txt wouldn't work, giving me the above error!
renaming the subfolder from "site" to "src" fixed the problem! Maybe pip is looking for "site-packages"? Crazy.
For me, it turned out to be a permissions problem on site-packages. Since it's only my dev environment, I raised the permissions and everything is working again:
sudo chmod -R a+rwx /path/to/my/venv/lib/python2.7/site-packages/
I had this problem when I had activated my virtualenv as a different user than the one who created it. It seems to be a permission problem. I discovered this when I tried the answer by #cwc and saw this in the output:
Installing easy_install script to /path/env/bin
error: /path/env/bin/easy_install: Permission denied
Switching back to the user that created the virtualenv, then running the original pip install command went without problems. Hope this helps!
I had this problem today as well. I only got the problem inside the virtual env.
The solution for me was deactivating the virtual env, deleting and then uninstalling virtualenv with pip and reinstalling it. After that I created a new virtual env for my project, then pip worked fine both inside the virtual environment as in the normal environment.
Looks like they have moved away from bitbucket and are now on github (https://github.com/pypa/setuptools)
Command to run is:
wget https://bootstrap.pypa.io/ez_setup.py -O - | sudo python
If you are encountering this issue with an application installed via conda, the solution (as stated in this bug report) is simply to install setup-tools with:
conda install setuptools
On Windows, with python 3.7, this worked for me:
pip install --upgrade setuptools --user
--user installs packages in your home directory, which doesn't require admin privileges.
Apparently you're missing setuptools. Some virtualenv versions use distribute instead of setuptools by default. Use the --setuptools option when creating the virtualenv or set the VIRTUALENV_SETUPTOOLS=1 in your environment.
None of the posted answers worked for me, so I reinstalled pip and it worked!
sudo apt-get install python-setuptools python-dev build-essential
sudo easy_install pip
pip install --upgrade setuptools
(reference: http://www.saltycrane.com/blog/2010/02/how-install-pip-ubuntu/)
In my case, I had 2 python versions installed initially and later I had deleted the older one. So while creating the virtual environment
virtualenv venv
was referring to the uninstalled python
What worked for me
python3 -m virtualenv venv
Same is true when you are trying to use pip.
I came across this answer when I was trying to follow this guide for OSX. What worked for me was, after running python get-pip, I had to ALSO easy_install pip. That fixed the issue of not being able to run pip at all. I did have a bunch of old macport stuff installed. That may have conflicted.
On windows, I installed pip downloaded from www.lfd.uci.edu/~gohlke/pythonlibs/ then encontered this problem.
So I should have installed setuptools(easy_install) first.
just reinstall your setuptools by :
$ sudo wget https://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz#md5=7df2a529a074f613b509fb44feefefe74e
$ tar -zxvf setuptools-0.6c11.tar.gz
$ cd setuptools-0.6c11/
$ sudo python setup.py build
$ sudo python setup.py install
$ sudo pip install --upgrade setuptools
then everything will be fine.
I use CentOS 6.7, and my python was just upgrade from 2.6.6 to 2.7.11, after tried so many different answer, finally the following one does the job:
sudo yum install python-devel
Hope help someone in the same situation.
I ran into this problem after updating my Ubuntu build. It seems to have gone through and removed set up tools in all of my virtual environments.
To remedy this I reinstalled the virtual environment back into the target directory. This cleaned up missing setup tools and got things running again.
e.g.:
~/RepoDir/TestProject$ virtualenv TestEnvironmentDir
For me a good fix was to use --no-download option to virtualenv (VIRTUALENV_NO_DOWNLOAD=1 tox for tox.)
On Opensuse 42.1 the following fixed this issue:
zypper in python-Pygments