繁体   English   中英

使用 pip 在开发模式下安装本地 package 时找不到 setuptools

[英]setuptools not found when installing local package in development mode with pip

我正在开发 Python package,并希望使用pip在开发模式下安装它。 当我运行pip install时,我得到一个ModuleNotFoundError告诉我缺少setuptools

$ pip install -e my-package/
...
  Running setup.py develop for my-package
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/home/user/my-package/setup.py'"'"'; __file__='"'"'/home/user/my-package/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' develop --no-deps --user --prefix=
         cwd: /home/user/my-package/
    Complete output (3 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    ModuleNotFoundError: No module named 'setuptools'

这让我很困惑,因为我确实有安装工具:

$ sudo apt-get install python3-setuptools
[sudo] password for user: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3-setuptools is already the newest version (45.2.0-1).
The following packages were automatically installed and are no longer required:
  espeak-ng-data gir1.2-gstreamer-1.0 libao-common libao4 libaudio2 libdotconf0 libespeak-ng1
  libfprint-2-tod1 libllvm9 libllvm9:i386 libpcaudio0 libsonic0 libspeechd2 python3-brlapi python3-click
  python3-colorama python3-louis python3-pyatspi python3-speechd sound-icons
  speech-dispatcher-audio-plugins xbrlapi
Use 'sudo apt autoremove' to remove them.
0 to upgrade, 0 to newly install, 0 to remove and 231 not to upgrade.

我可以在常规 python 中正确导入它:

$ python
Python 3.9.5 (default, Nov 23 2021, 15:27:38) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import setuptools
>>> 

我什至可以调用命令中出错的确切部分,而我自己不会出错!

$ /usr/bin/python -c 'import io, os, sys, setuptools, tokenize'
$

为什么pip找不到setuptools? 还值得注意的是pip install my-package在开发模式下没有-e标志。

我的 python/pip 可执行文件:

$ which python
/usr/bin/python            [a symlink to /usr/bin/python3.9]
$ which python3
/usr/bin/python3           [a symlink to /usr/bin/python3.8]
$ which pip
/home/user/.local/bin/pip
$ which pip3
/home/user/.local/bin/pip3

我以前遇到过这个问题,以下步骤对我有用。

  1. 使用 pip 安装setuptools
    Pypi 页面: https://pypi.org/project/setuptools/

     python -m pip install setuptools
  2. 验证是否安装了setuptools

     python -m pip list

    在此处输入图像描述

  3. 再次尝试重新安装 package。

     python -m pip install -e my-package/

执行这个:

sudo python setup.py develop

从 package 目录最终工作。 我无法解释为什么其他方法不起作用,但这是我的问题的解决方法。

如果什么都不起作用,只有当......

将您的代码上传到 GitHub 并从那里安装。 这对我有用。

像这样安装它:

pip install git+https://github.com/sarimbinwaseem/rsimageconvertor.git@main
pip install git+<link to repo.git>@<branch>

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM