首页 > 解决方案 > 如何从源文件(.tgz)在 Ubuntu virtualenv 中安装 python 3.8

问题描述

我无法安装软件包,pip install <packagename>因为我在安全墙后面。

我需要在最初具有 python 3.5.2 的 Ubuntu 16.04 服务器的 virtualenv 中安装 python 3.8

为此,我virtualenv-20.0.28-py2.py3-none-any.whl在(手动)安装所有依赖项之后手动安装在服务器上。然后我通过virtualenv pytorchpytorch是虚拟环境的名称)创建了一个 virtualenv,并通过source pytorch/bin/activate.

现在我处于环境模式

(pytorch) 用户@ubuntu:~/my_packages$

当我这样做 pip install Python-3.8.0.tgz时输出以下错误:

Processing ./Python-3.8.0.tgz
ERROR: Command errored out with exit status 1:
 command: /home/user/my_packages/pytorch/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-9npp4vja/setup.py'"'"'; __file__='"'"'/tmp/pip-req-build-9npp4vja/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-1d52yt0i
     cwd: /tmp/pip-req-build-9npp4vja/
Complete output (9 lines):
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/pip-req-build-9npp4vja/setup.py", line 2433, in <module>
    main()
  File "/tmp/pip-req-build-9npp4vja/setup.py", line 2392, in main
    set_compiler_flags('LDFLAGS', 'PY_LDFLAGS_NODIST')
  File "/tmp/pip-req-build-9npp4vja/setup.py", line 85, in set_compiler_flags
    sysconfig.get_config_vars()[compiler_flags] = flags + ' ' + py_flags_nodist
TypeError: Can't convert 'NoneType' object to str implicitly
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

如何将 python 3.8 安装到pytorch环境中?

请注意,我只能手动安装软件包

标签: pythonvirtualenvsetup.py

解决方案


Virtualenv 要求您实际安装了所需的 python 版本。

根据“安全墙”的含义,pip install <>它仍然适用于典型的用户范围安装,但它只会将模块安装到您的本地站点模块(~/.local/lib/python...)中。

有多种方法可以运行不同版本的 python,而无需在系统范围内安装它们。最后,您可以简单地下载 python 二进制文件并运行它,但这并不实际管理。作为替代方案,您可以使用anaconda 或 pyenv 之类的东西。


推荐阅读