【问题标题】:Error "can't create or remove files in install directory" when installing by source code in Python在 Python 中通过源代码安装时出现“无法在安装目录中创建或删除文件”错误
【发布时间】:2020-06-28 20:25:43
【问题描述】:

我正在尝试在云 Linux 中设置我的 Python 环境。我将工作文件夹“Artem's_strategy”,其中包含源代码setup.py,从本地PC复制​​到云端LInux系统。尝试安装 setup.py 时出现以下错误

[ec2-user@ip-xxx Artem's_strategy]$ python3 setup.py install
running install
error: can't create or remove files in install directory

The following error occurred while trying to add or remove files in the
installation directory:

    [Errno 2] No such file or directory: '/usr/local/lib/python3.7/site-packages/test-easy-install-2160.write-test'

The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

    /usr/local/lib/python3.7/site-packages/

This directory does not currently exist.  Please create it and try again, or
choose a different installation directory (using the -d or --install-dir
option).

在其他线程中,我以使用--install-dir 的形式找到了解决方案,这会带来以下错误:

[ec2-user@ip-xxx~]$ /home/ec2-user/Artem\'s_strategy/setup.py --install-dir=/usr/local/lib/python3.7/site-packages
: No such file or directory

查看文件夹我们可以看到setup.py存在于该文件夹中:

[ec2-user@ip-xxx Artem's_strategy]$ ls -la
total 1480
-rwxr-xr-x  1 ec2-user ec2-user     354 Mar 17 15:51 setup.py

因此,我们将不胜感激您对从源代码 setup.py 进行安装的帮助。

【问题讨论】:

  • 你运行的是什么版本的python?
  • Python 版本 3.7.6
  • 试试我的答案,可能只是不同目录的情况。

标签: python linux


【解决方案1】:

如果你进入终端并执行:

python3 -m site

它应该给你一个类似于以下的响应:

sys.path = [
    '/home/tyler',
    '/usr/lib/python36.zip',
    '/usr/lib/python3.6',
    '/usr/lib/python3.6/lib-dynload',
    '/home/tyler/.local/lib/python3.6/site-packages',
    '/usr/local/lib/python3.6/dist-packages',
    '/usr/lib/python3/dist-packages',
]
USER_BASE: '/home/tyler/.local' (exists)
USER_SITE: '/home/tyler/.local/lib/python3.6/site-packages' (exists)
ENABLE_USER_SITE: True

使用它,您可以确定您的site-packages 的存储目录并使用

--install-dir

参数来安装它。希望这会有所帮助!

【讨论】:

  • > [ec2-user@ip-xxx Artem's_strategy]$ setup.py --install-dir=/home/ec2-user/.local/lib/python3.7/site-packages -bash: setup.py: command not found
  • 试试:python3 setup.py --install-dir=/home/ec2-user/.local/lib/python3.7/site-packages -bash: setup.py: command not found'
  • 回复是usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] or: setup.py --help [cmd1 cmd2 ...] or: setup.py --help-commands or: setup.py cmd --help error: option --install-dir not recognized
  • 哦,你只需要在setup.py之后,--install-dir之前输入install
  • 出现同样的问题:[ec2-user@ip-172-31-2-41 strategy]$ python3 setup.py install --install-dir=/home/ec2-user/.local/lib/python3.7/site-packages usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] or: setup.py --help [cmd1 cmd2 ...] or: setup.py --help-commands or: setup.py cmd --help error: option --install-dir not recognized
【解决方案2】:

找到站点包的安装位置后,在命令中使用 --prefix=location。

python3 setup.py install prefix=C:\\Users\\User\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python38\\site-packages

【讨论】:

  • python setup.py install --prefix=C:\\Users\\User\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\\LocalCache\\local-packages \\Python38\\site-packages 对我有用。
【解决方案3】:

我遵循了 Tylerr 的回答:https://stackoverflow.com/a/60727896/13916894,但使用 --prefix 而不是 --install-dir 并且它有效。

【讨论】:

    【解决方案4】:

    你应该试试这个:

    python setup.py install --user || exit 1
    

    来源:https://github.com/hughperkins/pytorch/issues/8

    【讨论】:

    • python setup.py install --user 对我来说已经足够了,谢谢!
    【解决方案5】:

    不是 100% 确定它是否会起作用,但我的 WSL 上的 Flask Restful 也有类似的问题

    对我有用的是在获得完全权限后从https://flask-restful.readthedocs.io/en/latest/installation.html 运行整个设置

    sudo su
    

    【讨论】:

      猜你喜欢
      • 2015-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-16
      • 2012-05-12
      • 1970-01-01
      • 2020-07-14
      • 2013-10-15
      相关资源
      最近更新 更多