我刚刚将我的操作系统切换到 Ubuntu 16.04(第一次使用 Linux)。
我按照以下指南成功安装了 Python 3.6: http://docs.python-guide.org/en/latest/starting/install3/linux/
我按照在这个堆栈溢出线程中找到的答案安装了 pip: https://stackoverflow.com/questions/42662104/how-to-install-pip-for-python-3-6-on-ubuntu-16-10
一切都运行良好,但是,当我尝试使用安装 discord.py 模块时python3.6 -m pip install -U discord.py
,它尝试安装的所有内容都会出现权限错误。
Collecting discord.py
Collecting aiohttp<1.1.0,>=1.0.0 (from discord.py)
Collecting websockets<4.0,>=3.1 (from discord.py)
Using cached websockets-3.4-cp36-cp36m-manylinux1_x86_64.whl
Collecting chardet (from aiohttp<1.1.0,>=1.0.0->discord.py)
Using cached chardet-3.0.4-py2.py3-none-any.whl
Collecting multidict>=2.0 (from aiohttp<1.1.0,>=1.0.0->discord.py)
Using cached multidict-3.1.3-cp36-cp36m-manylinux1_x86_64.whl
Collecting async-timeout (from aiohttp<1.1.0,>=1.0.0->discord.py)
Using cached async_timeout-1.3.0-py3-none-any.whl
Installing collected packages: chardet, multidict, async-timeout, aiohttp, websockets, discord.py
Found existing installation: chardet 2.3.0
Uninstalling chardet-2.3.0:
Exception:
Traceback (most recent call last):
File "/usr/lib/python3.6/shutil.py", line 544, in move
os.rename(src, real_dst)
PermissionError: [Errno 13] Permission denied: '/usr/lib/python3/dist- packages/chardet' -> '/tmp/pip-kssx4kah-uninstall/usr/lib/python3/dist- packages/chardet'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/usr/local/lib/python3.6/dist-packages/pip/commands/install.py", line 342, in run
prefix=options.prefix_path,
File "/usr/local/lib/python3.6/dist-packages/pip/req/req_set.py", line 778, in install
requirement.uninstall(auto_confirm=True)
File "/usr/local/lib/python3.6/dist-packages/pip/req/req_install.py", line 754, in uninstall
paths_to_remove.remove(auto_confirm)
File "/usr/local/lib/python3.6/dist-packages/pip/req/req_uninstall.py", line 115, in remove
renames(path, new_path)
File "/usr/local/lib/python3.6/dist-packages/pip/utils/__init__.py", line 267, in renames
shutil.move(old, new)
File "/usr/lib/python3.6/shutil.py", line 556, in move
rmtree(src)
File "/usr/lib/python3.6/shutil.py", line 480, in rmtree
_ rmtree_safe_fd(fd, path, onerror)
File "/usr/lib/python3.6/shutil.py", line 438, in _rmtree_safe_fd
onerror(os.unlink, fullname, sys.exc_info())
File "/usr/lib/python3.6/shutil.py", line 436, in _rmtree_safe_fd
os.unlink(name, dir_fd=topfd)
PermissionError: [Errno 13] Permission denied: 'jpcntx.py'
这只是我收到的错误消息之一,我还收到其他错误消息,例如
PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.6/dist-packages/websockets'
和
PermissionError: [Errno 13] Permission denied: /usr/local/lib/python3.6/dist-packages/async_timeout
也
PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.6/dist-packages/multidict-3.1.3.dist-info'
答案1
请花一些时间阅读有关 Ubuntu 和 Linux 整体工作原理的知识,该命令应该是:
sudo -H pip install <package_name>
请注意以下几点:
如果你这样做
pip --version
,pip3 --version
你会看到该命令支持的 python 版本pip
:pip 9.0.1 from /usr/local/lib/python3.5/dist-packages (python 3.5)
如果你这样做
pip2 --version
,那么我们会看到python 2.*
:pip 8.1.1 from /usr/lib/python2.7/dist-packages (python 2.7)
Python 已经存在,因此需要重新安装它。
在 Ubuntu 中
pip
使用,但pip3
使用python 3.*
pip2
python 2.*
重要的:
-H, --set-home
Request that the security policy set the HOME environment variable to the home directory specified by the target user's password database
entry. Depending on the policy, this may be the default behavior.