我想在使用 创建的任何虚拟环境中安装 pip venv
,但该get-pip.py
脚本需要该distutils
软件包,而该软件包未安装在我正在使用的服务器中,并且我没有 root 访问权限。有什么办法可以做到吗?
服务器有Ubuntu 18.04,安装的python版本是3.6.9。
请注意,我可以创建虚拟环境而无需pip
使用python3 -m venv name
.
另请注意,这个问题不同于这个,因为只有当distutils
软件包安装在系统中时才有效。
答案1
据我所知 distutils 是Python 标准库的一部分,至少对于 Python 3 来说是这样。如果您没有安装它,那么您的 Python 安装一定是错误的(可能是托管提供商故意这样做的)。
无论如何,distutils 的来源可以是在这里找到。您只需要在受影响的系统上获取它的副本(通过git clone
或通过下载并提取 tarball),然后进行PYTHONPATH
相应设置以使 get-pip.py 正常工作:
9d3194663b77% git clone https://github.com/pypa/distutils
Cloning into 'distutils'...
remote: Enumerating objects: 1474, done.
remote: Counting objects: 100% (1474/1474), done.
remote: Compressing objects: 100% (659/659), done.
remote: Total 13343 (delta 890), reused 1362 (delta 811), pack-reused 11869
Receiving objects: 100% (13343/13343), 5.14 MiB | 22.78 MiB/s, done.
Resolving deltas: 100% (9592/9592), done.
9d3194663b77% cd distutils/distutils
9d3194663b77% ls
README bcppcompiler.py config.py dep_util.py extension.py log.py py38compat.py text_file.py versionpredicate.py
__init__.py ccompiler.py core.py dir_util.py fancy_getopt.py msvc9compiler.py spawn.py unixccompiler.py
_msvccompiler.py cmd.py cygwinccompiler.py dist.py file_util.py msvccompiler.py sysconfig.py util.py
archive_util.py command debug.py errors.py filelist.py py35compat.py tests version.py
9d3194663b77% cd ..
9d3194663b77% PYTHONPATH=. python3 ~/get-pip.py
Defaulting to user installation because normal site-packages is not writeable
Collecting pip
Downloading pip-21.0.1-py3-none-any.whl (1.5 MB)
|________________________________| 1.5 MB 7.1 MB/s
Collecting setuptools
Downloading setuptools-52.0.0-py3-none-any.whl (784 kB)
|________________________________| 784 kB 39.9 MB/s
Collecting wheel
Downloading wheel-0.36.2-py2.py3-none-any.whl (35 kB)
Installing collected packages: wheel, setuptools, pip
WARNING: The script wheel is installed in '/home/test/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The scripts pip, pip3 and pip3.7 are installed in '/home/test/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-21.0.1 setuptools-52.0.0 wheel-0.36.2