【问题标题】:Syntax error when trying to install ssl library in Python using pip [duplicate]尝试使用 pip 在 Python 中安装 ssl 库时出现语法错误 [重复]
【发布时间】:2021-10-06 11:04:54
【问题描述】:

我正在尝试在docs.python.org执行代码

import socket
import ssl

hostname = 'www.python.org'
context = ssl.create_default_context()

with socket.create_connection((hostname, 443)) as sock:
    with context.wrap_socket(sock, server_hostname=hostname) as ssock:
        print(ssock.version())

我安装了从Shining Light Productions下载的Win64OpenSSL_Light-1_1_1L

在目录 Windows\System32 中安装了 libcrypto-1_1-x64.dll v 1.1.1.12。 Python 版本是 3.9。

当我尝试从 Pycharm 内(以及从以管理员身份运行的外部 cmd 窗口)pip install ssl 时,它会崩溃并显示以下输出:

Collecting ssl  
  Using cached ssl-1.16.tar.gz (33 kB)  
    ERROR: Command errored out with exit status 1:  
     command: 'C:\Users\chribonn\.virtualenvs\ssl01\Scripts\python.exe' -c 'import io, os, sys,setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\chribonn\\AppData\\Local\\Temp\\pip-install-jiqpumyk\\ssl_bb978a5b89144b28940340898b82f710\\setup.py'"'"'; __file__='"'"'C:\\Users\\chribonn\\AppData\\Local\\Temp\\pip-install-jiqpumyk\\ssl_bb978a5b89144b28940340898b82f710\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"',open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code =f.read().replace('"'"'\r\n'"'"','"'"'\n'"'"');f.close();exec(compile(code,__file__,'"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\chribonn\AppData\Loca

l\Temp\pip-pip-egg-info-mozgaod0'

     cwd: C:\Users\chribonn\AppData\Local\Temp\pip-install-jiqpumyk\ssl_bb978a5b89144b28940340898b82f710\  
Complete output (6 lines):  
Traceback (most recent call last):  
  File "<string>", line 1, in <module>  
  File "C:\Users\chribonn\AppData\Local\Temp\pip-install-jiqpumyk\ssl_bb978a5b89144b28940340898b82f710\setup.py", line 33  
    print 'looking for', f  
          ^  
SyntaxError: Missing parentheses in call to 'print'. Did you mean print('looking for', f)?  
----------------------------------------  

【问题讨论】:

  • 你升级你的pip版本了吗?您的错误是因为您正在运行 Python 2.x 打印。您的库版本可能有问题。
  • 那个库没用。 SSL 必须编译成 Python。如果丢失,您应该检查您的安装方法。
  • @Rizquuula:我在最后一个点
  • @KlausD。谢谢,解决了我的问题

标签: python pip


【解决方案1】:

@KlausD 回答的主题。

ssl 是 Python 3.9 的一部分,无需 pip install ssl。

【讨论】:

    猜你喜欢
    • 2023-02-18
    • 2021-03-16
    • 1970-01-01
    • 2021-06-06
    • 2018-12-13
    • 1970-01-01
    • 2012-08-03
    • 1970-01-01
    • 2020-07-09
    相关资源
    最近更新 更多