测试失败:/home/mona/.local/lib/python3.8/sitepackages/不支持.pth文件错误:错误的安装目录或PYTHONPATH

2024-03-28 16:12:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用Python虚拟环境安装Git Repo的包。当我使用它的setup.py文件时,我得到以下错误。我该怎么修

mona@goku:~/research/code/IP-Net/src/lib/models/networks/py_utils/_cpools$ python setup.py install --user
running install
Checking .pth file support in /home/mona/.local/lib/python3.8/site-packages/
/home/mona/venv/ipnet/bin/python3 -E -c pass
TEST FAILED: /home/mona/.local/lib/python3.8/site-packages/ does NOT support .pth files
error: bad install directory or PYTHONPATH

You are attempting to install a package to a directory that is not
on PYTHONPATH and which Python does not read ".pth" files from.  The
installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

    /home/mona/.local/lib/python3.8/site-packages/

and your PYTHONPATH environment variable currently contains:

    '~/venv/ipnet/lib/python3.8/site-packages'

Here are some of your options for correcting the problem:

* You can choose a different installation directory, i.e., one that is
  on PYTHONPATH or supports .pth files

* You can add the installation directory to the PYTHONPATH environment
  variable.  (It must then also be on PYTHONPATH whenever you run
  Python and want to use the package(s) you are installing.)

* You can set up the installation directory to support ".pth" files by
  using one of the approaches described here:

  https://setuptools.readthedocs.io/en/latest/easy_install.html#custom-installation-locations


Please make the appropriate changes to your system and try again.

我有:

$ pip freeze
numpy==1.20.0
torch==1.7.1
typing-extensions==3.7.4.3
$ echo $PYTHONPATH
~/venv/ipnet/lib/python3.8/site-packages

$ ls ~/venv/ipnet/lib/python3.8/site-packages
total 152K
drwxrwxr-x  3 mona mona 4.0K Feb  2 19:34 ..
-rw-rw-r--  1 mona mona  126 Feb  2 19:34 easy_install.py
drwxrwxr-x  6 mona mona 4.0K Feb  2 19:34 setuptools
drwxrwxr-x  2 mona mona 4.0K Feb  2 19:34 setuptools-44.0.0.dist-info
drwxrwxr-x  2 mona mona 4.0K Feb  2 19:34 pip-20.0.2.dist-info
drwxrwxr-x  5 mona mona 4.0K Feb  2 19:34 pip
drwxrwxr-x  2 mona mona 4.0K Feb  2 19:34 pkg_resources-0.0.0.dist-info
drwxrwxr-x  5 mona mona 4.0K Feb  2 19:34 pkg_resources
-rw-rw-r--  1 mona mona  82K Feb  2 19:42 typing_extensions.py
drwxrwxr-x  2 mona mona 4.0K Feb  2 19:42 typing_extensions-3.7.4.3.dist-info
drwxrwxr-x  2 mona mona 4.0K Feb  2 19:42 __pycache__
drwxrwxr-x 18 mona mona 4.0K Feb  2 19:42 numpy
drwxrwxr-x  2 mona mona 4.0K Feb  2 19:42 numpy.libs
drwxrwxr-x  2 mona mona 4.0K Feb  2 19:42 numpy-1.20.0.dist-info
drwxrwxr-x 29 mona mona 4.0K Feb  2 19:42 torch
drwxrwxr-x 11 mona mona 4.0K Feb  2 19:42 caffe2
drwxrwxr-x 16 mona mona 4.0K Feb  2 19:42 .
drwxrwxr-x  2 mona mona 4.0K Feb  2 19:42 torch-1.7.1.dist-info

代码回购位于:https://github.com/vaesl/IP-Net

我的~/.bashrc中有以下内容,并且已经有了它的源代码。它属于我为git repo制作的Python Virt Env:

export PYTHONPATH="~/venv/ipnet/lib/python3.8/site-packages"

Tags: installthetopyinfolibpackagesdist
1条回答
网友
1楼 · 发布于 2024-03-28 16:12:30

正如用户metatoaster所建议的,我做了以下工作:

  1. 评论了我添加到~/.bashrc的这一行,并将其来源:

    #export PYTHONPATH="~/venv/ipnet/lib/python3.8/site-packages"

  2. 删除了此处的 user标志:

    python setup.py install

相关问题 更多 >