Python控制台脚本可执行文件在复制包后不存在。

huangapple go评论68阅读模式
英文:

Python console script executable does not exist after copying package

问题

我的Python包的构建过程需要创建一个虚拟环境,将包安装到服务器上的venv中,运行测试,然后将文件和venv复制到另一台服务器上。我的setup.py中有一个控制台脚本入口点:

setup(
    ...,
    entry_points={
        "console_scripts": [
            "foo = mypackage.main:main",
        ]
    },
)

当我尝试在服务器上使用控制台脚本时,它无法找到可执行文件,因为它被安装到了不同服务器上的虚拟环境中。

我尝试在setup函数的options关键字中使用相对路径来设置可执行文件,关键字是build_scriptsexecutable

如何确保控制台脚本使用已激活的虚拟环境的可执行文件?

英文:

The build process for my python package requires creating a virtual environment and installing the package into venv on a server, running tests, then copying the files and venv onto another server. My setup.py has a console script entry point:

setup(
    ...,
    entry_points={
        "console_scripts": [
            "foo = mypackage.main:main",
        ]
    },
)

When I try to use the console script on the server, it cannot find the executable because it was installed into the virtual environment on a different server.

I tried to set the executable to use a relative path in the setup function options keyword with the key build_scripts, executable.

How can I ensure that the console script uses the executable of the virtual environment that is activated?

答案1

得分: 1

我可能并不完全理解情况,但我知道关于 Python venv 的一个注意事项是,它们无法轻松地迁移到不同的机器,因为 venv 本身包含了对生成它的机器规格的硬编码路径。我成功的方法是:1)从原始 venv 中提取模块作为 requirements.txt;2)在新机器上创建一个新的 venv;3)使用之前生成的 requirements.txt 文件重新构建原始 venv。这是我用来找出如何执行这些操作的线程链接:https://stackoverflow.com/a/49251593

英文:

I might not be 100% grasping the situation, but one caveat that I do know about python venv's is that they cannot be migrated to a different machine (easily) because there exist hard coded paths within the venv itself to the specifications of the machine it was generated on. What I've ended up having success with is 1) pulling the modules out of the original venv as a requirements.txt 2) make a new venv on the new machine 3) reconstitute the original venv using the generated requirements.txt file from before. Here's the thread I used to figure out how to do all that: https://stackoverflow.com/a/49251593

huangapple
  • 本文由 发表于 2023年6月8日 00:36:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/76425433.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定