Problems installing Pillow/PIL in virtual environment without sudo - python-2.7

I have a program that I can run from terminal (no virtual environment) where I install packages with the --user option. Now I want to organize the program in a proper way in Python 2.7 using requirements.txt, setup.py, etc.
To do this I created a virtual environment and I am installing all the necessary packages, so that I can do a "pip freeze > requirements.txt".
Unfortunately I cannot install PIL/Pillow. I used to get a problem with jpeg but I fixed that with "sudo apt-get install libjpeg-dev". Now with these:
pip install Pillow
pip install Pillow --allow-external Pillow --allow-unverified Pillow
I get a permission denied:
...
error: could not create '/home/kinkyboy/virtualenv/tantrix/lib/python2.7/site-packages/PIL': Permission denied
----------------------------------------
Cleaning up...
Command /home/kinkyboy/virtualenv/tantrix/bin/python -c "import setuptools, tokenize;__file__='/home/kinkyboy/virtualenv/tantrix/build/Pillow/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-S9cPV3-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/kinkyboy/virtualenv/tantrix/include/site/python2.7 failed with error code 1 in /home/kinkyboy/virtualenv/tantrix/build/Pillow
Storing debug log for failure in /home/kinkyboy/.pip/pip.log
If I use sudo it works and with --user it doesn't, but obviously these commands do not install in the virtual environment.
Am I missing something?

The solution was to chown the path to the virtual environment. Make sure both ~/.cache/pip and the path to the virtual environment are both owned by the user. In my case the second was not
sudo chown -R your_username:your_username path/to/virtuaelenv/
See #Vingtoft here:
StackOverflow 19471972

Related

pip install mysqlclient error django

I am currently using MySQL 8.0 as database for my Django project. I am working with Python 3.6 version and have installed pip to load python modules from internet. I haven't faced issues while loading packages other than mysqlclient using pip.
I issued the command pip install mysqlclient and end up with following message and installation gets aborted:
"c:\users\anirudh\appdata\local\programs\python\python36-32\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\Anirudh\\AppData\\Local\\Temp\\pip-install-xer9o7aw\\mysqlclient\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\Anirudh\AppData\Local\Temp\pip-record-t3br6ckm\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\Anirudh\AppData\Local\Temp\pip-install-xer9o7aw\mysqlclient\
I am using visual studio 2017 and followed the link below fix this issue but no luck.
https://dimitri.janczak.net/2017/05/20/python-3-6-visual-studio-2017/
I tried to install mysqlclient using pip. But i did not succeed. I was able to install it using:
conda install mysqlclient
And it worked fine for me.

error: invalid command 'bdist_wheel'

On a RHEL machine
I have some old Django projects that I'm moving to a new server, these were written for Python2.6, Django1.4.3
I've installed python2.7, created the virtualenvs in my home directory, adjusted paths and references to the Python version.
I created a virtualenv for Python2.7:
virtualenv -p python2.7 ~/.virtualenvs/my_site/
When I activate the virtualenv and then cd into the web site directory and run
pip install -r requirements.txt
after successfully fetching all the libs, the following error is displayed for every line in requirements.txt:
Building wheels for collected packages: MySQL-python, Pillow...etc
Running setup.py bdist_wheel for MySQL-python ... error
Complete output from command /home/my_user/.virtualenvs/my_site/bin/python2.7 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-96k9a4/MySQL-python/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-ngSbQU --python-tag cp27:
usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: -c --help [cmd1 cmd2 ...]
or: -c --help-commands
or: -c cmd --help
error: invalid command 'bdist_wheel'
I've found many other similar questions on stackexchange and other sites, and tried the fixes but no luck!
Why can I not create a wheel in python?
Why is python setup.py saying invalid command 'bdist_wheel' on Travis CI?
Can't build wheel - error: invalid command 'bdist_wheel'
I have pip 10.0.1
wheel IS installed (through pip install wheel), I've also run the following in my virtual env:
pip install --upgrade pip ('Requirement already up-to-date')
pip install setuptools --upgrade ('Requirement already up-to-date')
python setup.py bdist_wheel ('error: invalid command 'bdist_wheel'')
What else can I look at to fix this?
Not sure why, but uninstalling wheel fixed it
I uninstalled wheel with a view to reinstalling it, but it worked without reinstalling.
pip uninstall wheel

Sentry compile fails with " error: command 'gcc' failed with exit status 1"

Been trying to install Sentry on CentOS 6.5. I have installed the prerequisites i.e Python 2.7.9
[root#localhost poduori]# python -V
Python 2.7.9
I used pyenv to change from the pre-installed python version 2.6.6 (pyenv install 2.7.9). When I try to install sentry I get the below output and error;
NB: I had already run it once hence it using cached.
pip2.7 install sentry
The full error output can be found here https://www.dropbox.com/s/64w6b7dswgzs9cb/Sentry_error.txt?dl=0
or
Sentry error txt file
A summary of the error I'm getting is below
error: command 'gcc' failed with exit status 1
----------------------------------------
Command "/root/.pyenv/versions/2.7.9/bin/python2.7 -c "import setuptools, tokenize;__file__='/tmp/pip-build-PSGsNT/cffi/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-UYMAyw-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-PSGsNT/cffi
The output was too long to post here so I used dropbox instead.
libffi is already installed.
root#localhost user]# rpm -qa|grep libffi
libffi-3.0.5-3.2.el6.x86_64
I already installed all the development tools,
yum groupinstall "Development tools" (including gcc compiler) but I still get the same error. Kindly assist.
ERROR: /bin/sh: xslt-config: command not found
** make sure the development packages of libxml2 and libxslt are installed **
c/_cffi_backend.c:13:17: error: ffi.h: No such file or directory
You need to install dev packages first one (it let you out of this w/ pre-built libs) is libxslt-dev, second one is python-dev. Exact names depends on your distro.
Using ubuntu i solved this by:
Installing setuptools with :
wget https://bootstrap.pypa.io/ez_setup.py -O - | python
created a file requisits.sh
inserted the content:
#! /bin/bash
sudo apt-get update
sudo apt-get install build-essential
sudo apt-get install python-dev
sudo apt-get install setuptools
sudo apt-get install python-pip
sudo apt-get install libxslt1-dev
sudo apt-get install libxslt-dev
sudo apt-get install libxml2-dev
sudo apt-get install libz-dev
sudo apt-get install libffi-dev
sudo apt-get install libssl-dev
put execution chmod +x requisits.sh
executed:
./requisits.sh
entered the password and answered y/n when prompted.
and finally :
if using virtualenv:
pip install -U sentry
else
sudo pip install -U sentry

pip install python-novaclient is failing due to netifaces.c

I'm trying to install OpenStack python novaclient using pip install python-novaclient
This task fails: netifaces.c:185:6 #error You need to add code for your platform
I have no idea what code it wants.
Does anyone understand this?
I also had this problem, and resolved by
sudo yum install python-devel python-pip
sudo yum -y install gcc
Same issue in awx_task container in AWX project (Centos 7), trying to execute
pip install python-openstackclient
Error was:
Command "/usr/bin/python2 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-LTchWP/netifaces/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-86uBIZ-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-LTchWP/netifaces/
Solved with:
yum install python-devel python-pip gcc
Hope it will help someone!
This has to do with the order that libraries are imported in the netifaces setup.py and is fixed in version 10.3+ (which you need to install from source). Here's how to install 10.4 (current latest release):
mkdir -p /tmp/install/netifaces/
cd /tmp/install/netifaces && wget -O "netifaces-0.10.4.tar.gz" "https://pypi.python.org/packages/source/n/netifaces/netifaces-0.10.4.tar.gz#md5=36da76e2cfadd24cc7510c2c0012eb1e"
tar xvzf netifaces-0.10.4.tar.gz
cd netifaces-0.10.4 && python setup.py install
I landed on this question while doing something similar:
pip install rackspace-novaclient
And this is what my error looked like:
Command "/usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-G5GwYu/netifaces/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-Jugr2a-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-G5GwYu/netifaces
After reading the entire output logs, I realized I was missing "gcc" and just needed to install it.
On CentOS 7, my fix was:
yum -y install gcc && pip install rackspace-novaclient

Pandas Seaborn Install

On Ubuntu 12.04 LTS running Python 2.7 I'm getting an install error from attempting to add the great looking Seaborn plotting package to my existing Pandas environment which is running fine.
Here's a snippet from the console containing the errors:
~$ pip install seaborn
running install_lib
creating /usr/local/lib/python2.7/dist-packages/seaborn
error: could not create '/usr/local/lib/python2.7/dist-packages/seaborn':
Permission denied
Cleaning up...
Command /usr/bin/python -c "import setuptools, tokenize;__file__='/tm/pip_build_moj0/seaborn/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-LvVao5-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_mojo/seaborn
Storing debug log for failure in /home/mojo/.pip/pip.log
Anyone have a resolution tip not available on the Seaborn github site?
I think the easiest way is to use sudo:
sudo pip install seaborn
It requires sudo permission to write to usr/local/lib.
Note: If you're using anaconda you won't need sudo to install via pip, once you've conda installed pip, though seaborn may also be available via conda.
Personal installation is a good habit to get into:
pip install --user seaborn
However, there is an even easier way: as of writing python XY maintains up-to-date builds of pandas and seaborn (among other useful packages), so all you have to do is
sudo add-apt-repository ppa:pythonxy/pythonxy-devel
sudo apt-get update
sudo apt-get install python-seaborn python-pandas
Note that this will only work with python 2.x; you will still need pip3 to install the python 3.x packages.