簡體   English   中英

如何使用本地 python 安裝在 ubuntu 14.04 上安裝 pip

[英]How to install pip on ubuntu 14.04 using a local python installation

我知道,這個問題可能看起來很簡單,但相信我,你並不了解整個故事。

我正在運行 Ubuntu 14.04。

$ python -V
Python 2.7.6
$ python3 -V
Python 3.4.3

我安裝了更新的 python 版本(3.8),因為我想安裝 Discord.py

$ python3.8 -V
Python 3.8.2

當我嘗試使用以下步驟安裝 pip 時,出現以下錯誤:

$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 1764k  100 1764k    0     0  1351k      0  0:00:01  0:00:01 --:--:-- 1363k
$ python3.8 get-pip.py
Defaulting to user installation because normal site-packages is not writeable
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
ERROR: Could not find a version that satisfies the requirement pip (from versions: none)
ERROR: No matching distribution found for pip
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping

哦,是的...我嘗試使用原始 python3 安裝安裝 pip 並且成功但是...

$ pip3 -V
pip 1.5.4 from /usr/lib/python3/dist-packages (python 3.4)

但是在嘗試安裝 Discord.py 時:

$ python3 -m pip install -U discord.py
Downloading/unpacking discord.py
  Downloading discord.py-1.3.3-py3-none-any.whl (676kB): 676kB downloaded
Downloading/unpacking websockets>=6.0,!=7.0,!=8.0,!=8.0.1,<9.0 (from discord.py)
  Downloading websockets-8.1.tar.gz (58kB): 58kB downloaded
  Running setup.py (path:/tmp/pip_build_sujit/websockets/setup.py) egg_info for package websockets
    Traceback (most recent call last):
      File "<string>", line 17, in <module>
      File "/tmp/pip_build_sujit/websockets/setup.py", line 12, in <module>
        long_description = (root_dir / 'README.rst').read_text(encoding='utf-8')
    AttributeError: 'PosixPath' object has no attribute 'read_text'
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):

  File "<string>", line 17, in <module>

  File "/tmp/pip_build_sujit/websockets/setup.py", line 12, in <module>

    long_description = (root_dir / 'README.rst').read_text(encoding='utf-8')

AttributeError: 'PosixPath' object has no attribute 'read_text'

----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /tmp/pip_build_sujit/websockets
Storing debug log for failure in /home/sujit/.pip/pip.log

在過去的兩天里,我到處尋找解決方案,這讓我發瘋。 At first I thought I just needed to install the python ssl module to install pip on python3,8, but then to do that pip was required in the first place. 那是我放棄的時候,我願意接受建議,請幫助我!

這是我嘗試使用 python3.6 安裝 Discord.py 時發生的情況:

$ python3.6 -m pip --version
pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6)
sujit@sujit-MXC061:/opt/Python-3.6.3$ python3.6 -m pip install -U discord.py
Collecting discord.py
  Downloading https://files.pythonhosted.org/packages/f6/12/a3cfceefd625c39a2d6f9f52ffad57f1b3fcb9906eaa0eeafd2392f10deb/discord.py-1.3.3-py3-none-any.whl (676kB)
    100% |████████████████████████████████| 686kB 282kB/s 
Collecting websockets!=7.0,!=8.0,!=8.0.1,<9.0,>=6.0 (from discord.py)
  Downloading https://files.pythonhosted.org/packages/c8/34/947fff38511d40daa350f63a1b1a972767c90a30c0f6115a622642b48a4d/websockets-8.1-cp36-cp36m-manylinux1_i686.whl (72kB)
    100% |████████████████████████████████| 81kB 1.4MB/s 
Collecting aiohttp<3.7.0,>=3.6.0 (from discord.py)
  Downloading https://files.pythonhosted.org/packages/c2/f7/f0ad3dbace4762fef5d80aa4124b41bf218e4c4dd6d387a86cede707d9a4/aiohttp-3.6.2-py3-none-any.whl (441kB)
    100% |████████████████████████████████| 450kB 346kB/s 
Collecting attrs>=17.3.0 (from aiohttp<3.7.0,>=3.6.0->discord.py)
  Downloading https://files.pythonhosted.org/packages/a2/db/4313ab3be961f7a763066401fb77f7748373b6094076ae2bda2806988af6/attrs-19.3.0-py2.py3-none-any.whl
Collecting typing-extensions>=3.6.5; python_version < "3.7" (from aiohttp<3.7.0,>=3.6.0->discord.py)
  Downloading https://files.pythonhosted.org/packages/0c/0e/3f026d0645d699e7320b59952146d56ad7c374e9cd72cd16e7c74e657a0f/typing_extensions-3.7.4.2-py3-none-any.whl
Collecting async-timeout<4.0,>=3.0 (from aiohttp<3.7.0,>=3.6.0->discord.py)
  Downloading https://files.pythonhosted.org/packages/e1/1e/5a4441be21b0726c4464f3f23c8b19628372f606755a9d2e46c187e65ec4/async_timeout-3.0.1-py3-none-any.whl
Collecting yarl<2.0,>=1.0 (from aiohttp<3.7.0,>=3.6.0->discord.py)
  Downloading https://files.pythonhosted.org/packages/d6/67/6e2507586eb1cfa6d55540845b0cd05b4b77c414f6bca8b00b45483b976e/yarl-1.4.2.tar.gz (163kB)
    100% |████████████████████████████████| 163kB 550kB/s 
Collecting multidict<5.0,>=4.5 (from aiohttp<3.7.0,>=3.6.0->discord.py)
  Downloading https://files.pythonhosted.org/packages/61/b4/475114b3f1671da634f89239e61038f8742d9ac13aa34b32a05bf8022d22/multidict-4.7.5.tar.gz (50kB)
    100% |████████████████████████████████| 51kB 756kB/s 
Collecting chardet<4.0,>=2.0 (from aiohttp<3.7.0,>=3.6.0->discord.py)
  Downloading https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl (133kB)
    100% |████████████████████████████████| 143kB 709kB/s 
Collecting idna-ssl>=1.0; python_version < "3.7" (from aiohttp<3.7.0,>=3.6.0->discord.py)
  Downloading https://files.pythonhosted.org/packages/46/03/07c4894aae38b0de52b52586b24bf189bb83e4ddabfe2e2c8f2419eec6f4/idna-ssl-1.1.0.tar.gz
Collecting idna>=2.0 (from yarl<2.0,>=1.0->aiohttp<3.7.0,>=3.6.0->discord.py)
  Downloading https://files.pythonhosted.org/packages/89/e3/afebe61c546d18fb1709a61bee788254b40e736cff7271c7de5de2dc4128/idna-2.9-py2.py3-none-any.whl (58kB)
    100% |████████████████████████████████| 61kB 1.4MB/s 
Installing collected packages: websockets, attrs, typing-extensions, async-timeout, multidict, idna, yarl, chardet, idna-ssl, aiohttp, discord.py
Exception:
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/usr/local/lib/python3.6/site-packages/pip/commands/install.py", line 342, in run
    prefix=options.prefix_path,
  File "/usr/local/lib/python3.6/site-packages/pip/req/req_set.py", line 784, in install
    **kwargs
  File "/usr/local/lib/python3.6/site-packages/pip/req/req_install.py", line 851, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "/usr/local/lib/python3.6/site-packages/pip/req/req_install.py", line 1064, in move_wheel_files
    isolated=self.isolated,
  File "/usr/local/lib/python3.6/site-packages/pip/wheel.py", line 345, in move_wheel_files
    clobber(source, lib_dir, True)
  File "/usr/local/lib/python3.6/site-packages/pip/wheel.py", line 316, in clobber
    ensure_dir(destdir)
  File "/usr/local/lib/python3.6/site-packages/pip/utils/__init__.py", line 83, in ensure_dir
    os.makedirs(path)
  File "/usr/local/lib/python3.6/os.py", line 220, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.6/site-packages/websockets-8.1.dist-info'

以下是在 Ubuntu 14 和 Python 3.6 中安裝discord的步驟:

$ docker pull ubuntu:trusty
$ docker run -it ubuntu:trusty
# apt update
# apt install -y build-essential checkinstall libreadline-gplv2-dev \
    libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev \
    libbz2-dev libffi-dev zlib1g-dev wget
# cd /opt
# wget https://www.python.org/ftp/python/3.6.10/Python-3.6.10.tgz
# tar xzv Python-3.6.10.tgz && cd Python-3.6.10
# ./configure --enable-optimizations
# make altinstall
# python3.6 -m pip install --upgrade pip
# python3.6 -m pip install discord
# python3.6 -c "import discord; print(discord.__version__)"
1.3.3

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM