简体   繁体   English

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

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

I am developing a Python package, and would like to install it in development mode using pip .我正在开发 Python package,并希望使用pip在开发模式下安装它。 When I run pip install , I get a ModuleNotFoundError telling me that setuptools is missing:当我运行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'

This confuses me, as I do indeed have 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.

and I can import it without error in regular python:我可以在常规 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
>>> 

I can even invoke the exact part of the command that's giving an error without getting any error myself!我什至可以调用命令中出错的确切部分,而我自己不会出错!

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

Why doesn't pip find setuptools?为什么pip找不到setuptools? It's also worth noting that pip install my-package works without the -e flag for development mode.还值得注意的是pip install my-package在开发模式下没有-e标志。

My python/pip executables:我的 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

I had this issue previously and the following steps worked for me.我以前遇到过这个问题,以下步骤对我有用。

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

     python -m pip install setuptools
  2. Verify that setuptools is installed.验证是否安装了setuptools

     python -m pip list

    在此处输入图像描述

  3. Attempt to re-install your package again.再次尝试重新安装 package。

     python -m pip install -e my-package/

Executing this:执行这个:

sudo python setup.py develop

from the package directory worked in the end.从 package 目录最终工作。 I can't explain why the other methods didn't work, but this was a workaround for my problem.我无法解释为什么其他方法不起作用,但这是我的问题的解决方法。

If nothing is working, only if...如果什么都不起作用,只有当......

Upload your code to GitHub and install from there.将您的代码上传到 GitHub 并从那里安装。 This worked for me.这对我有用。

Install it like this:像这样安装它:

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