python - setup.py install 使用 virtualenv 进行开发 - 安装目录或 PYTHONPATH 错误

标签 python virtualenv setup.py virtualenvwrapper

我的主文件夹中有一个名为 Packages 的文件夹。在这个文件夹中我想开发一些包。为了测试它们,我尝试使用安装包

python setup.py install develop

当然是在环境内部。这给了我以下输出

develop
running install
running bdist_egg
running egg_info
writing BACnetScapy.egg-info/PKG-INFO
writing top-level names to BACnetScapy.egg-info/top_level.txt
writing dependency_links to BACnetScapy.egg-info/dependency_links.txt
reading manifest file 'BACnetScapy.egg-info/SOURCES.txt'
writing manifest file 'BACnetScapy.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
creating build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/BACnetScapy
copying build/lib.linux-x86_64-2.7/BACnetScapy/BACnetLayers.py -> build/bdist.linux-x86_64/egg/BACnetScapy
copying build/lib.linux-x86_64-2.7/BACnetScapy/BACnetTags.py -> build/bdist.linux-x86_64/egg/BACnetScapy
copying build/lib.linux-x86_64-2.7/BACnetScapy/__init__.py -> build/bdist.linux-x86_64/egg/BACnetScapy
copying build/lib.linux-x86_64-2.7/BACnetScapy/BACnetFunctions.py -> build/bdist.linux-x86_64/egg/BACnetScapy
copying build/lib.linux-x86_64-2.7/BACnetScapy/BACnetConstants.py -> build/bdist.linux-x86_64/egg/BACnetScapy
byte-compiling build/bdist.linux-x86_64/egg/BACnetScapy/BACnetLayers.py to BACnetLayers.pyc
byte-compiling build/bdist.linux-x86_64/egg/BACnetScapy/BACnetTags.py to BACnetTags.pyc
byte-compiling build/bdist.linux-x86_64/egg/BACnetScapy/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/BACnetScapy/BACnetFunctions.py to BACnetFunctions.pyc
byte-compiling build/bdist.linux-x86_64/egg/BACnetScapy/BACnetConstants.py to BACnetConstants.pyc
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying BACnetScapy.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying BACnetScapy.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying BACnetScapy.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying BACnetScapy.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating 'dist/BACnetScapy-1.0-py2.7.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing BACnetScapy-1.0-py2.7.egg
Copying BACnetScapy-1.0-py2.7.egg to /home/lk/virtualenvs/FuzzingEnv/lib/python2.7/site-packages
Adding BACnetScapy 1.0 to easy-install.pth file

Installed /home/lk/virtualenvs/FuzzingEnv/lib/python2.7/site-packages/BACnetScapy-1.0-py2.7.egg
Processing dependencies for BACnetScapy==1.0
Finished processing dependencies for BACnetScapy==1.0
running develop
Checking .pth file support in build/bdist.linux-x86_64/egg
/home/lk/virtualenvs/FuzzingEnv/bin/python -E -c pass
TEST FAILED: build/bdist.linux-x86_64/egg does NOT support .pth files
error: bad install directory or PYTHONPATH

You are attempting to install a package to a directory that is not
on PYTHONPATH and which Python does not read ".pth" files from.  The
installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

    build/bdist.linux-x86_64/egg

and your PYTHONPATH environment variable currently contains:

    ''

Here are some of your options for correcting the problem:

* You can choose a different installation directory, i.e., one that is
  on PYTHONPATH or supports .pth files

* You can add the installation directory to the PYTHONPATH environment
  variable.  (It must then also be on PYTHONPATH whenever you run
  Python and want to use the package(s) you are installing.)

* You can set up the installation directory to support ".pth" files by
  using one of the approaches described here:

  https://pythonhosted.org/setuptools/easy_install.html#custom-installation-locations

Please make the appropriate changes for your system and try again.

所以问题似乎是在包文件夹中自动创建的 build 文件夹不在 PYTHONPATH 上 - 但为什么会这样呢?我应该如何将其添加到 PYTHONPATH 中?我尝试添加此文件夹

add2virtualenv /home/lk/Packages/BACnetScapy/build

但这也不起作用。 我做错了什么?

这是我的setup.py

from setuptools import setup

setup(
    name="BACnetScapy",
    author="lk",
    version="1.0",
    packages=["BACnetScapy"],
    include_package_data=True
)

文件夹看起来像这样

/BACnetScapy
    |
    |-/BACnetScapy
    |       |- some.py
    |       |- modules.py
    |       |- __init__.py
    |       |-/data # a folder containing some data the package needs
    |
    |-setup.py 

最佳答案

命令应该是python setup.pydevelop,而不是python setup.py installdevelop

关于python - setup.py install 使用 virtualenv 进行开发 - 安装目录或 PYTHONPATH 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35013746/

相关文章:

python - 使用 virtualenv 恢复 `--no-site-packages` 选项

python - 如何告诉 setuptools 从 src/mypackage 获取我的包

python - 如何将图像添加到 Python 包索引文档中?

python - 如何在 Django 管理模型中上传多个文件

python - 如何使用高级完整文件搜索

linux - 与其他开发人员共享虚拟环境

python - 为什么我不能使用 --target 和 --editable 调用 pip?

python - "ImportError: cannot import name"使用flask_sqlalchemy

python - 在 flask 中,我如何在另一个 View 中调用另一个函数/路由的数据,如下所述

python - 已经满足要求-/usr/lib/python3/dist-packages(0.8.0)中的pymysql