在没有 sudo 的虚拟环境中安装 Pillow/PIL 时出现问题

Problems installing Pillow/PIL in virtual environment without sudo

我有一个程序,我可以从终端(无虚拟环境)运行 使用 --user 选项安装软件包。现在我想在 Python 2.7 中使用 requirements.txt、setup.py 等以适当的方式组织程序。 为此,我创建了一个虚拟环境并安装了所有必要的软件包,这样我就可以执行 "pip freeze > requirements.txt"。

很遗憾,我无法安装 PIL/Pillow。我曾经遇到过 jpeg 的问题,但我用 "sudo apt-get install libjpeg-dev" 解决了这个问题。现在有了这些:

pip install Pillow
pip install Pillow --allow-external Pillow --allow-unverified Pillow

我的权限被拒绝:

...
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

如果我使用 sudo 它可以工作,而使用 --user 它则不能,但显然这些命令不会安装在虚拟环境中。 我错过了什么吗?

解决方案是更改虚拟环境的路径。确保 ~/.cache/pip 和虚拟环境的路径都归用户所有。在我的例子中,第二个不是

sudo chown -R your_username:your_username path/to/virtuaelenv/

请在此处查看@Vingtoft: Whosebug 19471972