Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing python-dev in virtualenv

I am trying to install mysqlclient for python in my virtualenv. It fails with the following:

 #include "Python.h"

                ^

compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

After some research, i found out that i require python-dev installation. I have it installed in my main directories (i.e /usr/bin ... ) but its not installed virtualenv but each time i type:

sudo apt-get install python-dev

I get the following response:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
python-dev is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 453 not upgraded.

Showing its availability, outside the virtualenv mysqlclient installs properly. The issue is how to rectify python-dev installation into the virtualenv

like image 256
Subomi Avatar asked Aug 14 '17 18:08

Subomi


People also ask

Do I need to install python in virtualenv?

Installing virtualenv venv is included in the Python standard library and requires no additional installation. If you are using venv, you may skip this section. virtualenv is used to manage Python packages for different projects.

How do I install a specific version of python in virtualenv?

By default, that will be the version of python that is used for any new environment you create. However, you can specify any version of python installed on your computer to use inside a new environment with the -p flag : $ virtualenv -p python3. 2 my_env Running virtualenv with interpreter /usr/local/bin/python3.

How do I add python path to virtual environment?

Just put a file with a . pth extension (any basename works) in your virtualenv's site-packages folder, e.g. lib\python2. 7\site-packages , with the absolute path to the directory containing your package as its only contents.


2 Answers

I am currently having issue in Ubuntu 20 where the default python is python 3.8. This causes issue when I try to install Pillow in a virtualenv created by pipenv that need to use python 3.9.

The simplest solution I found so far is to install python-dev for 3.9

sudo apt install python3.9-dev

Previously I install python3-dev which always default to 3.8

like image 155
wiz_lee Avatar answered Oct 16 '22 14:10

wiz_lee


Maybe not the best way but my solution was installing miniconda. You can also probably try the larger Anaconda distribution. I believe these distributions have built-in python-dev.

like image 23
Jeremee Avatar answered Oct 16 '22 14:10

Jeremee