在过去的几个月里,我一直在使用 python 3 开发一个程序。我已经对其进行了一段时间的测试,它似乎可以正常工作。因此,我尝试在 DSM/Synology(型号:DS209+,版本:DSM 4.2-3259)上启动并运行它。可悲的是,我对这种环境一无所知。所以我从 Synology 套件中心安装了 python3 (3.3.2-0005) 并让它运行起来。运行我的代码有效。唯一的问题是,我的程序使用了“请求”库。但是我就是无法让 pip 运行。为了安装 pip,我尝试在 PuTTY 中使用以下行。
curl -k https://bootstrap.pypa.io/get-pip.py | python3
我希望 pip 下载/安装并使用它来获取请求库。但是后来发生了这种情况,我不知道我做错了什么:
The directory '/var/services/homes/admin/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/var/services/homes/admin/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pip
Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)
100% |################################| 1.3MB 131kB/s
Collecting setuptools
Downloading setuptools-38.2.4-py2.py3-none-any.whl (489kB)
100% |################################| 491kB 305kB/s
Collecting wheel
Downloading wheel-0.30.0-py2.py3-none-any.whl (49kB)
100% |################################| 51kB 296kB/s
Installing collected packages: pip, setuptools, wheel
Exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.3/distutils/sysconfig.py", line 449, in _init_posix
with open(filename) as file:
FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/include/python3.3m/pyconfig.h'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/tmp/tmpdqp31o/pip.zip/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/tmp/tmpdqp31o/pip.zip/pip/commands/install.py", line 342, in run
prefix=options.prefix_path,
File "/tmp/tmpdqp31o/pip.zip/pip/req/req_set.py", line 784, in install
**kwargs
File "/tmp/tmpdqp31o/pip.zip/pip/req/req_install.py", line 851, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "/tmp/tmpdqp31o/pip.zip/pip/req/req_install.py", line 1064, in move_wheel_files
isolated=self.isolated,
File "/tmp/tmpdqp31o/pip.zip/pip/wheel.py", line 247, in move_wheel_files
prefix=prefix,
File "/tmp/tmpdqp31o/pip.zip/pip/locations.py", line 153, in distutils_scheme
i.finalize_options()
File "/usr/local/lib/python3.3/distutils/command/install.py", line 313, in finalize_options
(prefix, exec_prefix) = get_config_vars('prefix', 'exec_prefix')
File "/usr/local/lib/python3.3/distutils/sysconfig.py", line 531, in get_config_vars
func()
File "/usr/local/lib/python3.3/distutils/sysconfig.py", line 456, in _init_posix
raise DistutilsPlatformError(my_msg)
distutils.errors.DistutilsPlatformError: invalid Python installation: unable to open /usr/local/include/python3.3m/pyconfig.h (No such file or directory)
似乎使用 sudo -H 可以解决这个问题。但是我不知道该怎么做以及从哪里开始。谷歌搜索这个问题也没有多大帮助,因为我发现的东西要么太模糊以至于我无法理解,要么他们已经安装了 pip。我希望这个问题也不会太含糊。
原文由 user8357325 发布,翻译遵循 CC BY-SA 4.0 许可协议
使用新的 venv pip 时自动可用。例如:
之后,您可以将 pip 升级到当前版本:
这样还有一个好处就是用pip安装包不会破坏系统python。
要自动激活您的环境,您可以创建一个
.profile
:然后让它的内容看起来像这样: