简体   繁体   English

Python 使用 setup.py 手动将 package 安装到虚拟环境

[英]Python manually install package to virtual environment with setup.py

I am developing using Python 3.7.我正在使用 Python 3.7 进行开发。

I'm trying to write a small Python package and install it into a virtual environment for testing.我正在尝试编写一个小型 Python package 并将其安装到虚拟环境中进行测试。 The library is structured like this:该库的结构如下:

my_package/
    src/
        my_package/
            __init__.py
            utilities.py
            some_data_files/
    setup.py
    README.md
    ...

When I create virtual environment and try to install:当我创建虚拟环境并尝试安装时:

(env) C:\Users\path\to\my_package python setup.py install

The output is: output 是:

running install
running bdist_egg
running egg_info
writing my_package.egg-info\PKG-INFO
writing dependency_links to my_package.egg-info\dependency_links.txt
writing top-level names to my_package.egg-info\top_level.txt
reading manifest file 'my_package.egg-info\SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'my_package.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
warning: install_lib: 'build\lib' does not exist -- no Python modules to install

creating build\bdist.win-amd64\egg
creating build\bdist.win-amd64\egg\EGG-INFO
copying my_package.egg-info\PKG-INFO -> build\bdist.win-amd64\egg\EGG-INFO
copying my_package.egg-info\SOURCES.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying my_package.egg-info\dependency_links.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying my_package.egg-info\top_level.txt -> build\bdist.win-amd64\egg\EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating 'dist\my_package-0.0.1-py3.7.egg' and adding 'build\bdist.win-amd64\egg' to it
removing 'build\bdist.win-amd64\egg' (and everything under it)
Processing my_package-0.0.1-py3.7.egg
Copying my_package-0.0.1-py3.7.egg to c:\users\jon\development\my_package_env\env\lib\site-p
ackages
Adding my_package 0.0.1 to easy-install.pth file

Installed c:\users\jon\development\my_package_env\env\lib\site-packages\my_package-0.0.1-py3
.7.egg
Processing dependencies for my_package==0.0.1
Finished processing dependencies for my_package==0.0.1

There is an egg file in site-packages but no directory containing any of the files from the my_package directory. site-packages中有一个 egg 文件,但没有包含my_package目录中任何文件的目录。 This is my first time writing a Python package for distribution, and I'm using the Python documentation as a guide, but I'm not ready to upload anywhere and would like to test locally.这是我第一次编写 Python package 进行分发,我正在使用Python 文档作为指南,但我不想在任何地方上传和测试。 Can someone let me know what steps I must take to be able to test my package locally in a virtual environment?有人可以告诉我必须采取哪些步骤才能在虚拟环境中本地测试我的 package 吗?

  • Create a source distribution and a built distribution of your project, with these commands:使用以下命令创建项目的源代码分发和构建分发:
    • (env) C:\Users\jon\development\my_package_env>python3 setup.py sdist
    • (env) C:\Users\jon\development\my_package_env>python3 setup.py bdist_wheel
  • Note the two newly created archives in the dist/ directory注意dist/目录中新创建的两个档案
  • Try to install these distributions in fresh virtual environments:尝试在新的虚拟环境中安装这些发行版:
    • C:\Users\jon\development\my_package_env>python3 -m venv sdist-env
    • C:\Users\jon\development\my_package_env>sdist-env\Scripts\activate.bat
    • (sdist-env) C:\Users\jon\development\my_package_env>pip install dist\my_package-0.0.1.tar.gz
    • (sdist-env) C:\Users\jon\development\my_package_env>deactivate
    • C:\Users\jon\development\my_package_env>python3 -m venv wheel-env
    • C:\Users\jon\development\my_package_env>wheel-env\Scripts\activate.bat
    • (wheel-env) C:\Users\jon\development\my_package_env>pip install dist\my_package-0.0.1-py3-none-any.whl

Once you're confident with this, you might want to look at tox to automate the testing of your project in multiple virtual environments.一旦您对此充满信心,您可能希望查看tox以在多个虚拟环境中自动测试您的项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过setup.py安装的Python包 - Python package through setup.py install 在CentOS中是“ yum install package”还是“ python setup.py install”? - “yum install package” or “python setup.py install” in CentOS? 当他们从PyPI pip安装软件包时,从setup.py中访问用户激活的虚拟环境 - access the user's activated virtual environment from within setup.py when they pip install your package from PyPI Python setup.py 依赖语法,package 的多个环境标记? - Python setup.py dependency syntax, multiple environment markers for a package? 如何使用手动 setup.py 全局安装 python 包? - How to install a python package globally with manual setup.py? 无法使用 PIP 和 setup.py 安装 Python 密码学 package - Failed to install Python Cryptography package with PIP and setup.py 安装仅一个Python文件且没有setup.py的软件包 - Install a package that is only one Python file and has no setup.py PIP安装没有setup.py文件的Python包? - PIP install a Python Package without a setup.py file? 安装 Python package: setup.py install - error: no commands supplied - Installing Python package: setup.py install - error: no commands supplied 使用setup.py和wheels安装软件包依赖项 - Install package dependencies with setup.py and wheels
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM