Python virtualenv需要dist包来运行脚本

Python virtualenv需要dist包来运行脚本,python,linux,python-2.7,python-imaging-library,virtualenv,Python,Linux,Python 2.7,Python Imaging Library,Virtualenv,Python、virtualenv和linux-noob这三种语言 我有一个小型python项目,它使用/usr/local/lib/python2.7/dist包中的下载包(PyFPDF)。一切都很好 我已经读到使用virtualenv是一种更好的方法,因为它使项目和依赖项目的包彼此独立,并与主python系统分离 建立了virtualenv之后,我现在有: ~/python/project/folder |_py script file

Python、virtualenv和linux-noob这三种语言

我有一个小型python项目,它使用
/usr/local/lib/python2.7/dist包中的下载包(PyFPDF)。一切都很好

我已经读到使用virtualenv是一种更好的方法,因为它使项目和依赖项目的包彼此独立,并与主python系统分离

建立了virtualenv之后,我现在有:

~/python/project/folder
                 |_py script file
                 |_folder with some project related files
                 |_env folder

然而,当我运行脚本时,我收到一条关于缺少PIL的消息

我看到PIL实际上位于原始python设置中。
/usr/lib/python2.7/dist包/

我的env设置根本没有dist packages文件夹-链接或其他我认为是重点的地方,即env使用通用的系统范围的python包,但也允许您使用特定于项目的包

我对我最初的设置是如何工作的感到更加困惑,因为如上所述,我是从
/usr/local/lib/python2.7/dist-packages/
运行的,它没有PIL

显然,我不理解以下两者之间的细微差别:

/usr/local/lib/python2.7/dist包/
(无PIL)和

/usr/lib/python2.7/dist包/
(具有PIL)

总之,长短不一的是,为了让我的项目在env中运行,我在
/pythonproject/env/lib/python2.7/
中创建了一个
快捷方式
,该快捷方式链接到
/usr/lib/python2.7/dist-packages/

这个脚本现在运行得很好,但我忍不住觉得我已经破解了它,而且我没有真正使用virtualenv

我希望我的描述比泥浆稍微清晰一些。正如我所说的,我在三个方面都是无赖,但我正在尝试。希望有人能帮忙

编辑:这是我的命令行

user@dual-lt ~ $ cd /home/user/Documents/PyProjects/PDFproject

user@dual-lt ~/Documents/PyProjects/PDFproject $ ls env
bin  include  lib  local

user@dual-lt ~/Documents/PyProjects/PDFproject $ source env/bin/activate

(env)user@dual-lt ~/Documents/PyProjects/PDFproject $ which python
/home/user/Documents/PyProjects/PDFproject/env/bin/python

(env)user@dual-lt ~/Documents/PyProjects/PDFproject $ which pip
/home/user/Documents/PyProjects/PDFproject/env/bin/pip

(venv)user@dual-lt ~/Documents/PyProjects/PDFproject $ pip install pil
Requirement already satisfied (use --upgrade to upgrade): pil in /usr/lib/python2.7/dist-packages/PIL

Cleaning up...
(venv)user@dual-lt ~/Documents/PyProjects/PDFproject $
第二次编辑:

Downloading/unpacking pil

You are installing a potentially insecure and unverifiable file. Future versions of pip will default to disallowing insecure files.
Downloading PIL-1.1.7.tar.gz (506kB): 506kB downloaded
Running setup.py egg_info for package pil
WARNING: '' not a valid package name; please use only.-separated package names in setup.py

Installing collected packages: pil
Running setup.py install for pil
WARNING: '' not a valid package name; please use only.-separated package names in setup.py
building '_imaging' extension
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -IlibImaging -I/home/dan/Documents/PyProjects/PDF-IdCardStatic/venv/include -I/usr/local/include -I/usr/include -I/usr/include/python2.7 -c _imaging.c -o build/temp.linux-x86_64-2.7/_imaging.o
_imaging.c:75:20: fatal error: Python.h: No such file or directory
#include "Python.h"
                ^
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
Complete output from command /home/dan/Documents/PyProjects/PDF-IdCardStatic/venv/bin/python -c "import setuptools;__file__='/home/dan/Documents/PyProjects/PDF-IdCardStatic/venv/build/pil/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-GxHMlW-record/install-record.txt --single-version-externally-managed --install-headers /home/dan/Documents/PyProjects/PDF-IdCardStatic/venv/include/site/python2.7:
WARNING: '' not a valid package name; please use only.-separated package names in setup.py

running install

running build

running build_py

creating build

creating build/lib.linux-x86_64-2.7

copying PIL/__init__.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageFile.py -> build/lib.linux-x86_64-2.7

copying PIL/XbmImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageQt.py -> build/lib.linux-x86_64-2.7

copying PIL/GbrImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/XVThumbImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/CurImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/PalmImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageEnhance.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageFileIO.py -> build/lib.linux-x86_64-2.7

copying PIL/PSDraw.py -> build/lib.linux-x86_64-2.7

copying PIL/ArgImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/MicImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/PpmImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/PngImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageDraw2.py -> build/lib.linux-x86_64-2.7

copying PIL/TgaImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/FpxImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/FitsStubImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/FontFile.py -> build/lib.linux-x86_64-2.7

copying PIL/IptcImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/GimpGradientFile.py -> build/lib.linux-x86_64-2.7

copying PIL/GribStubImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageFilter.py -> build/lib.linux-x86_64-2.7

copying PIL/BdfFontFile.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageOps.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageMode.py -> build/lib.linux-x86_64-2.7

copying PIL/GdImageFile.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageCms.py -> build/lib.linux-x86_64-2.7

copying PIL/JpegImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/ImagePalette.py -> build/lib.linux-x86_64-2.7

copying PIL/ImagePath.py -> build/lib.linux-x86_64-2.7

copying PIL/BufrStubImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageWin.py -> build/lib.linux-x86_64-2.7

copying PIL/ImImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/Image.py -> build/lib.linux-x86_64-2.7

copying PIL/ExifTags.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageSequence.py -> build/lib.linux-x86_64-2.7

copying PIL/OleFileIO.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageGL.py -> build/lib.linux-x86_64-2.7

copying PIL/BmpImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/IcnsImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/PaletteFile.py -> build/lib.linux-x86_64-2.7

copying PIL/PsdImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/GimpPaletteFile.py -> build/lib.linux-x86_64-2.7

copying PIL/PcdImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/IcoImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/ImtImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/SunImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageFont.py -> build/lib.linux-x86_64-2.7

copying PIL/ContainerIO.py -> build/lib.linux-x86_64-2.7

copying PIL/PcxImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/SgiImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageGrab.py -> build/lib.linux-x86_64-2.7

copying PIL/WalImageFile.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageTransform.py -> build/lib.linux-x86_64-2.7

copying PIL/MspImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/MpegImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageDraw.py -> build/lib.linux-x86_64-2.7

copying PIL/EpsImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageColor.py -> build/lib.linux-x86_64-2.7

copying PIL/TiffImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageMath.py -> build/lib.linux-x86_64-2.7

copying PIL/PixarImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageTk.py -> build/lib.linux-x86_64-2.7

copying PIL/TiffTags.py -> build/lib.linux-x86_64-2.7

copying PIL/TarIO.py -> build/lib.linux-x86_64-2.7

copying PIL/DcxImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/McIdasImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/WmfImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/FliImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/Hdf5StubImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/PdfImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/SpiderImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/GifImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageChops.py -> build/lib.linux-x86_64-2.7

copying PIL/XpmImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageShow.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageStat.py -> build/lib.linux-x86_64-2.7

copying PIL/PcfFontFile.py -> build/lib.linux-x86_64-2.7

running build_ext

building '_imaging' extension

creating build/temp.linux-x86_64-2.7

creating build/temp.linux-x86_64-2.7/libImaging

x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -IlibImaging -I/home/dan/Documents/PyProjects/PDF-IdCardStatic/venv/include -I/usr/local/include -I/usr/include -I/usr/include/python2.7 -c _imaging.c -o build/temp.linux-x86_64-2.7/_imaging.o

_imaging.c:75:20: fatal error: Python.h: No such file or directory

#include "Python.h"

                ^

compilation terminated.

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

----------------------------------------
Cleaning up...
Command /home/dan/Documents/PyProjects/PDF-IdCardStatic/venv/bin/python -c "import setuptools;__file__='/home/dan/Documents/PyProjects/PDF-IdCardStatic/venv/build/pil/setup.py'

exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-GxHMlW-record/install-record.txt --single-version-externally-managed --install-headers /home/dan/Documents/PyProjects/PDF-IdCardStatic/venv/include/site/python2.7 failed with error code 1 in /home/dan/Documents/PyProjects/PDF-IdCardStatic/venv/build/pil

Storing complete log in /home/dan/.pip/pip.log`

理想情况下,您可以激活virtualenv,然后安装所有依赖项,包括
Pil
。谢谢,当今天第一次出现Pil错误时,我尝试从env运行pip install Pil,我收到一条消息说它已安装,但肯定不在我的环境中。我现在再试一次。@justinfay请查看原始问题中的编辑您是否还有指向/usr/lib/python2.7/dist-packages/的符号链接?在检查安装了哪些软件包时,Pip可能引用了这一点。删除此符号链接,然后再次尝试pip安装。好的,在internet上有很多关于最后错误的信息。我确实
sudo安装了python-dev
,然后回到我的env中并
pip安装了pil
。我现在在env/lib/python2.7/site-packages/文件夹中有一个pil文件夹。让我们看看这能给我带来什么。尽管有很多评论说放弃pil,改用枕头。我们需要调查一下。
Downloading/unpacking pil

You are installing a potentially insecure and unverifiable file. Future versions of pip will default to disallowing insecure files.
Downloading PIL-1.1.7.tar.gz (506kB): 506kB downloaded
Running setup.py egg_info for package pil
WARNING: '' not a valid package name; please use only.-separated package names in setup.py

Installing collected packages: pil
Running setup.py install for pil
WARNING: '' not a valid package name; please use only.-separated package names in setup.py
building '_imaging' extension
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -IlibImaging -I/home/dan/Documents/PyProjects/PDF-IdCardStatic/venv/include -I/usr/local/include -I/usr/include -I/usr/include/python2.7 -c _imaging.c -o build/temp.linux-x86_64-2.7/_imaging.o
_imaging.c:75:20: fatal error: Python.h: No such file or directory
#include "Python.h"
                ^
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
Complete output from command /home/dan/Documents/PyProjects/PDF-IdCardStatic/venv/bin/python -c "import setuptools;__file__='/home/dan/Documents/PyProjects/PDF-IdCardStatic/venv/build/pil/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-GxHMlW-record/install-record.txt --single-version-externally-managed --install-headers /home/dan/Documents/PyProjects/PDF-IdCardStatic/venv/include/site/python2.7:
WARNING: '' not a valid package name; please use only.-separated package names in setup.py

running install

running build

running build_py

creating build

creating build/lib.linux-x86_64-2.7

copying PIL/__init__.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageFile.py -> build/lib.linux-x86_64-2.7

copying PIL/XbmImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageQt.py -> build/lib.linux-x86_64-2.7

copying PIL/GbrImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/XVThumbImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/CurImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/PalmImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageEnhance.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageFileIO.py -> build/lib.linux-x86_64-2.7

copying PIL/PSDraw.py -> build/lib.linux-x86_64-2.7

copying PIL/ArgImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/MicImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/PpmImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/PngImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageDraw2.py -> build/lib.linux-x86_64-2.7

copying PIL/TgaImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/FpxImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/FitsStubImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/FontFile.py -> build/lib.linux-x86_64-2.7

copying PIL/IptcImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/GimpGradientFile.py -> build/lib.linux-x86_64-2.7

copying PIL/GribStubImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageFilter.py -> build/lib.linux-x86_64-2.7

copying PIL/BdfFontFile.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageOps.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageMode.py -> build/lib.linux-x86_64-2.7

copying PIL/GdImageFile.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageCms.py -> build/lib.linux-x86_64-2.7

copying PIL/JpegImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/ImagePalette.py -> build/lib.linux-x86_64-2.7

copying PIL/ImagePath.py -> build/lib.linux-x86_64-2.7

copying PIL/BufrStubImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageWin.py -> build/lib.linux-x86_64-2.7

copying PIL/ImImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/Image.py -> build/lib.linux-x86_64-2.7

copying PIL/ExifTags.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageSequence.py -> build/lib.linux-x86_64-2.7

copying PIL/OleFileIO.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageGL.py -> build/lib.linux-x86_64-2.7

copying PIL/BmpImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/IcnsImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/PaletteFile.py -> build/lib.linux-x86_64-2.7

copying PIL/PsdImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/GimpPaletteFile.py -> build/lib.linux-x86_64-2.7

copying PIL/PcdImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/IcoImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/ImtImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/SunImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageFont.py -> build/lib.linux-x86_64-2.7

copying PIL/ContainerIO.py -> build/lib.linux-x86_64-2.7

copying PIL/PcxImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/SgiImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageGrab.py -> build/lib.linux-x86_64-2.7

copying PIL/WalImageFile.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageTransform.py -> build/lib.linux-x86_64-2.7

copying PIL/MspImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/MpegImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageDraw.py -> build/lib.linux-x86_64-2.7

copying PIL/EpsImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageColor.py -> build/lib.linux-x86_64-2.7

copying PIL/TiffImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageMath.py -> build/lib.linux-x86_64-2.7

copying PIL/PixarImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageTk.py -> build/lib.linux-x86_64-2.7

copying PIL/TiffTags.py -> build/lib.linux-x86_64-2.7

copying PIL/TarIO.py -> build/lib.linux-x86_64-2.7

copying PIL/DcxImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/McIdasImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/WmfImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/FliImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/Hdf5StubImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/PdfImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/SpiderImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/GifImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageChops.py -> build/lib.linux-x86_64-2.7

copying PIL/XpmImagePlugin.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageShow.py -> build/lib.linux-x86_64-2.7

copying PIL/ImageStat.py -> build/lib.linux-x86_64-2.7

copying PIL/PcfFontFile.py -> build/lib.linux-x86_64-2.7

running build_ext

building '_imaging' extension

creating build/temp.linux-x86_64-2.7

creating build/temp.linux-x86_64-2.7/libImaging

x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -IlibImaging -I/home/dan/Documents/PyProjects/PDF-IdCardStatic/venv/include -I/usr/local/include -I/usr/include -I/usr/include/python2.7 -c _imaging.c -o build/temp.linux-x86_64-2.7/_imaging.o

_imaging.c:75:20: fatal error: Python.h: No such file or directory

#include "Python.h"

                ^

compilation terminated.

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

----------------------------------------
Cleaning up...
Command /home/dan/Documents/PyProjects/PDF-IdCardStatic/venv/bin/python -c "import setuptools;__file__='/home/dan/Documents/PyProjects/PDF-IdCardStatic/venv/build/pil/setup.py'

exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-GxHMlW-record/install-record.txt --single-version-externally-managed --install-headers /home/dan/Documents/PyProjects/PDF-IdCardStatic/venv/include/site/python2.7 failed with error code 1 in /home/dan/Documents/PyProjects/PDF-IdCardStatic/venv/build/pil

Storing complete log in /home/dan/.pip/pip.log`