gpt4 book ai didi

python - 将 python setup.py 安装到替代路径中找不到已安装的包

转载 作者:太空狗 更新时间:2023-10-30 01:24:15 25 4
gpt4 key购买 nike

我有一个测试设置文件,它是我为一个简单的“hello world”脚本制作的。我有一个名为 mytest 的包,它有一个函数 hello。现在,我有一个非常简单的 setup.py。如果我只运行 python setup.py install,一切正常。但是,如果我想将 lib 安装到主文件夹中 (python setup.py install --home=/home/blah),则该包不再可用(运行 import mytest在 python 中给我 ImportError: No module named mytest).

我应该手动将 pth 文件添加到 site-packages 文件夹中吗?我尝试了它(内容为 /home/blah/lib/python,我的包放在那里)并且导入 mytest 工作正常。它不应该自动完成吗?还是我错过了什么?

编辑:

安装输出:

ago@dellbert:~/py/mytest-0.1$ python setup.py install --home=/home/ago/py/running installrunning buildrunning build_pycopying src/mytest/mytest.py -> build/lib.linux-x86_64-2.6/mytestrunning build_scriptscopying and adjusting src/main.py -> build/scripts-2.6running install_libcopying build/lib.linux-x86_64-2.6/mytest/mytest.py -> /home/ago/py//lib/python/mytestbyte-compiling /home/ago/py//lib/python/mytest/mytest.py to mytest.pycrunning install_scriptscopying build/scripts-2.6/main.py -> /home/ago/py//binchanging mode of /home/ago/py//bin/main.py to 755running install_egg_infoRemoving /home/ago/py//lib/python/mytest-0.1.egg-infoWriting /home/ago/py//lib/python/mytest-0.1.egg-info

和setup.py:

from distutils.core import setupsetup(name='mytest',      description='test',      author='Ago',      author_email='email',      version='0.1',      package_dir={'mytest': 'src/mytest'},      packages=['mytest'],      scripts=['src/main.py']      )

文件夹结构:

-src:   -mytest:       __init__.py       mytest.py    main.pysetup.py

main.py 只是一个导入 mytest 并调用函数打印 hello world 的可执行文件。但我试图在 python 中运行 import mytest 来查看是否安装了 lib。

最佳答案

看来 python 至少统一了 Unix 和 Windows 环境中的参数。查看今天的 python 引用(https://docs.python.org/2/install/index.html,2017 年 12 月),它表明在这两个操作系统中您都可以使用 --prefix=<head installation path> .查看引用资料,第 "Alternate installation: Unix (the prefix scheme)" 部分和 "Alternate installation: Windows (the prefix scheme)" .我刚刚使用 Oct2Py(Octave-to-Python 转换器)对其进行了测试,使用 easy_install 或 pip 安装起来很麻烦,但这样做效果很好。

然后您的 python 包将位于(假设您使用 Python 2.7)<head installation path>/lib/python2.7/site-packages<head installation path>/lib/python2.7/dist-packages .

关于python - 将 python setup.py 安装到替代路径中找不到已安装的包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4405354/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com