【发布时间】:2020-05-20 20:12:12
【问题描述】:
我正在尝试设置一个合适的 Python 包进行分发,但我的 setup.py 文件的 console_scripts 属性遇到了问题。我的设置中有以下内容:
<...>
entry_points={"console_scripts": ["solve_cipher=cipher_solver.solve_cipher:main"]}
<...>
我已经打包并发送到测试 PyPI,然后在新的虚拟环境中安装我的打包。现在,solve_cipher 命令可用,但运行它会给我:
$ solve_cipher
Traceback (most recent call last):
File "/Users/markus/.virtualenvs/cipher_solver_debug_pypi/bin/solve_cipher", line 6, in <module>
from cipher_solver.solve_cipher import main
ModuleNotFoundError: No module named 'cipher_solver'
但是,如果我只是启动 Python 并运行相同的导入行,它就可以正常工作:
$ python
>>> from cipher_solver.solve_cipher import main
>>>
为什么会这样?我的项目布局如下:
cipher_solver
<...>
cipher_solver
consts.py
simple.py
solve_cipher.py
utils.py
<...>
setup.py
【问题讨论】:
-
which python?head -1 /Users/markus/.virtualenvs/cipher_solver_debug_pypi/bin/solve_cipher? -
@phd #!/Users/markus/.virtualenvs/cipher_solver_debug_pypi/bin/python3.7
-
看起来不错。和
which python一样吗?当您从命令行import cipher_solver时,当前目录是什么?setup.py所在的那个? -
谢谢!我解决了这个问题,请参阅下面的答案。
-
@phd 嗯,我想我说得太早了。是的,它们是相同的 Python 二进制文件,我从
setup.py所在的位置运行它。还有其他想法吗?
标签: python python-3.x setuptools