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
I want to install fenics in Ubuntu 20.
First I made a python environment using:
sudo apt install python3-venv
Then inside the folder I want to make an environment I open a terminal and use:
python3 -m venv myproject
myproject is the name of the environment I made.
I then activate my environment:
source myproject/bin/activate
To install fenics for this particular environment while I activated the environment, I use:
pip install fenics
I verify the installation using pip list which returns:
Package Version
-------------- --------------
fenics 2019.1.0
fenics-dijitso 2019.1.0
fenics-ffc 2019.1.0.post0
fenics-fiat 2019.1.0
fenics-ufl 2019.1.0
mpmath 1.1.0
numpy 1.19.4
pip 20.0.2
pkg-resources 0.0.0
setuptools 44.0.0
sympy 1.7.1
I try to import fenics using:
python -c "import fenics"
But I get the error below stating there is not fenics module:
raceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'fenics'
What is the problem? Hopefully, after successful installation of fenics, I can install Spyder and other python packages and will be able to use fenics inside spyder.
Edit
I want to install fenics in a python virtual environment.
The issue here is that fenics is just a meta-package and it does not contain any library that you can use in your Python code.
Quoting from the README for the fenics project :
This package contains a single file, setup.py, that allows all of the FEniCS Python components to be installed from PyPI using pip:
pip3 install fenics
Actual use of the library is done via
import ffc
All different components are under this package. For example, fenics-fiat is available as ffc.fiatinterface.
Fenics library of python
If you have installed pip than you have to use pip install fenics. If you have installed pip3 than `pip3 install fenics
I have already installed both.
sudo apt update
sudo apt install python3-pip
Install pip for Python 2 with:
sudo apt install python-pip
After doing pip3 install fenics,write python3 -c import ffc to import it. If this works, it has been imported. It is called ffc, not fenics
I am trying to install xlrd to read Excel files in python.
I have tried this: pip install -U pip setuptools. My macOS Mojave 10.4.3 has Python 2.7 which is where the default install goes to. But I have also installed Python3.7. How do I get pip install to my 3.7 directory?
I am on Mac machine(Catalina -version 10.15.5) and below pip3 command worked for me.
pip3 install xlrd
python version : 3.7.6
OS : Mac-Catalina(10.15.5)
Thanks to #Tapan Hegde, pip3 install xlrd worked from me, after installing the pip3, like this:
sudo apt update
apt install python3-pip
pip3 install xlrd
I reckon the easiest/cleanest solution would be to use a tool that isolates your python environment, such as virtualenv
Once installed, create a virtual env by specifying which version of python you want to use:
$> virtualenv -p python3 env
Note: puttin python3 directly works only for mac, with linux, you must specify the absolute path or your python binary.
And then 'activate' your environment:
$> source env/bin/activate
From here, any python or pip command you use will use python3.
$> pip install xlrd
Virtualenv has the advantage of not 'polluting' your local python installation, your can manage your pip modules installed more easily.
If you want more detail on how it works and the other alternatives, check this post
When pip install xlrd not work and in computer is still old version, then try do it with current version, for example pip install xlrd==2.0.1.
The current versions are here
I am trying to install mayavi via pip on my ubuntu 16.04 via shell. I am using python 3.6 via anaconda and already installed vtk and all other requirements but i get the above error when i try pip3 install mayavi or pip2 install mayavi.
Mayavi is packaged for ubuntu packages.ubuntu.com/xenial/mayavi2.
I suggest that you install with the command
sudo apt-get install mayavi2
instead, this will take care of installing a version that matches the vtk install on your system.
Try to rename libvtkOpenGLKitPython*.so file.
In my case it was:
cd /opt/conda/envs/pytorch-py3.6/lib/python3.6/site-packages/vtk
cp libvtkOpenGLKitPython36D-8.1.so libvtkOpenGLKitPython.so
and, maybe one more error with libxt6 file. Fix it:
apt install libxt6
i want to play with the lunar lander env from OpenAI gym.
In order to run this code I need to install Box2d, this is where my problems arise.
I am using ubuntu 16.04 with conda 4.3.21 and python 3.6.
When I tried to run the environment I received the error: ModuleNotFoundError: No module named '_Box2D'
So I tried the direct install of pybox2d:
https://github.com/pybox2d/pybox2d/blob/master/INSTALL.md
which yielded the same error message.
Then I tried to install from GitHub following the way outlined in https://github.com/cbfinn/gps/issues/34
$git clone https://github.com/pybox2d/pybox2d pybox2d_dev
$cd pybox2d_dev
$python setup.py build
$sudo python setup.py install
If I run this (in root environment which has python 3 or another new created environment with python 3) i get the result:
a lot of processing logs
Processing Box2D-2.3.2-py2.7-linux-x86_64.egg
creating /usr/local/lib/python2.7/dist-packages/Box2D-2.3.2-py2.7-linux-x86_64.egg
Extracting Box2D-2.3.2-py2.7-linux-x86_64.egg to /usr/local/lib/python2.7/dist-packages
Adding Box2D 2.3.2 to easy-install.pth file
Installed /usr/local/lib/python2.7/dist-packages/Box2D-2.3.2-py2.7-linux-x86_64.egg
Processing dependencies for Box2D==2.3.2
Finished processing dependencies for Box2D==2.3.2
So pybox2d is installed into the lib of the standard python 2 of ubuntu despite being in a python 3 conda environment.
So, I am looking for ways to install the pybox2d package for python 3 with conda 4.3.21
Installing Box2D from pip led me to the error described here when I tried to import it. Here's what worked for me on Python 3.6, as suggested in that GitHub issue:
conda install swig # needed to build Box2D in the pip install
pip install box2d-py # a repackaged version of pybox2d
Hey this question looks quite old but it seems no one really put the right answer in any where so just write this.
Follow the below two lines on your linux command:
$ sudo apt-get install build-essential python-dev swig python-pygame
$ pip install Box2D
---------Below is unnecessary details --------
Many wants to run Box2D based gym but it is sth you have to install by yourself like Mujoco series gym envs.
Many uses python 3.6 but the easiest way of installing Box2D, which is
$ conda install -c kne pybox2d
doesn't work cuz pybox2d has been maintained til py3.5
But directly doing
$ pip install Box2D
does not solve the issue. The error comes from swig given its error msg, but it's actually not.
$ sudo apt-get install build-essential python-dev swig python-pygame
This line always solve everything in one go.
I have been doing research based on Box2D envs but still foget this everytime I install this in a new env, so this is for me as well lol
Contribute: https://github.com/jonasschneider/box2d-py/blob/master/INSTALL.md
Btw, do not forget to double-check whether it is properly install.
In linux command
$ python --version
python 3.6. sthsth
$ python
>>> import numpy as np
>>> import gym
>>> env = gym.make('BipedalWalker-v2')
# If it does not give you error, then it's done!
You need to activate your environment:
source activate my_env_name
Then prompt changes to:
(my_env_name)
Now, install with pip and without sudo:
pip install pybox2d
sudo apt-get install swig
pip install pybox2d
Installing this way worked for me (also in a virtual env):
pip install box2d-py==2.3.8
I am running gym v 0.17.3.