在没有管理员权限的Windows上安装Python模块

7

我在工作笔记本上没有管理员权限。我的机器上已安装了Python和pip,版本号如下:

C:\Users\banand\AppData\Local\Programs\Python\Python36\Scripts>python --version
Python 3.6.1

C:\Users\banand\AppData\Local\Programs\Python\Python36\Scripts>pip --version
pip 9.0.1 from c:\users\banand\appdata\local\programs\python\python36\lib\site-packages (python 3.6)

我需要一种利用在线可用的各种Python模块的方法。例如 - colorama

按照说明,我尝试了以下命令,但没有成功:

C:\Users\banand\AppData\Local\Programs\Python\Python36\Scripts>pip install colorama --user
Collecting colorama
  Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x000001D431204F28>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it',)': /simple/colorama/
  Retrying (Retry(total=3, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x000001D431204A58>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it',)': /simple/colorama/
  Retrying (Retry(total=2, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x000001D431204780>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it',)': /simple/colorama/
  Retrying (Retry(total=1, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x000001D431204BA8>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it',)': /simple/colorama/
  Retrying (Retry(total=0, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x000001D431204898>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it',)': /simple/colorama/
  Could not find a version that satisfies the requirement colorama (from versions: )
No matching distribution found for colorama

我认为这可能与以下事实有关 - a. 我没有管理员权限,或者 b. 我在防火墙后面,因此正在执行某种形式的拦截
我想找出确切的问题,然后回答这个问题 - 是否有一种方法可以规避这些限制,并有一个可重复的方法来安装Python模块。
请注意,我在使用公司笔记本电脑,并且出于兴趣学习Python,因此我不想去请求管理员权限,也不想因为尝试在我的笔记本电脑上做一些不应该尝试的事情而陷入麻烦。
非常感谢您的帮助。

2
你尝试过从软件包下载页面下载列出的wheel(.whl)文件,然后使用pip install -U colorama-0.3.9-py2.py3-none-any.whl --user命令进行安装吗?从你发布的日志来看,这似乎是某种连接问题,可能是由于Windows防火墙设置引起的。 - metatoaster
@metatoaster,我已经尝试使用命令行安装,也尝试过下载压缩包文件。今天我发现了 wheel 文件,已经下载了,但还没有尝试,晚上稍后会尝试并更新。 - Bharat Anand
1
顺便说一下,在您的情况下没有必要进行--user安装。您已经在%LocalAppData%中拥有针对每个用户的安装,该安装应该已将其“Scripts”目录添加到PATH中。 --user安装使用漫游%AppData%目录,相应的“Scripts”目录不会添加到PATH中。 - Eryk Sun
1
你可能想要参加这样的课程:https://www.codecademy.com/learn/learn-python。它是免费的,所有的Python代码都在浏览器中完成,是一个很好的起点。 - sniperd
@metatoaster,wheel文件可用。耶!我为每个模块(\colorama、\pygame等)创建了单独的文件夹,并在相应的文件夹中下载了相应的wheel文件。接下来,在命令提示符上,导航到colorama文件夹并发出“pip install colorama”命令(感谢@eryksun建议的“PATH”修复)。魔法发生了!现在我想知道“import colorama”是如何获取模块/函数的。它是否仍需要wheel文件或这些模块已更新到我的Python安装程序中? - Bharat Anand
显示剩余4条评论
3个回答

6
这篇文章已经发布7个月了,但可以帮助其他人。 以下内容适用于Windows 10 Pro且没有管理员权限: python.exe -m pip install

4
  1. 安装Anaconda(不需要管理员权限) ->
  2. 打开Spyder ->
  3. 进入终端并输入 ->
import sys

!{sys.executable} -m pip install pandas

'C:\Program' is not recognized as an internal or external command, operable program or batch file. - The Singularity

0

我在Jupyter Notebook上尝试了一下,它完美地运行了:

代码:

import sys

!{sys.executable} -m pip install xarray

系统回答:

Collecting xarray
  Using cached https://files.pythonhosted.org/packages/10/6f/9aa15b1f9001593d51a0e417a8ad2127ef384d08129a0720b3599133c1ed/xarray-0.16.2-py3-none-any.whl
Requirement already satisfied: setuptools>=38.4 in c:\anaconda3\lib\site-packages (from xarray) (41.0.1)
Requirement already satisfied: numpy>=1.15 in c:\anaconda3\lib\site-packages (from xarray) (1.16.4)
Requirement already satisfied: pandas>=0.25 in c:\anaconda3\lib\site-packages (from xarray) (1.2.1)
Requirement already satisfied: pytz>=2017.3 in c:\anaconda3\lib\site-packages (from pandas>=0.25->xarray) (2019.1)
Requirement already satisfied: python-dateutil>=2.7.3 in c:\anaconda3\lib\site-packages (from pandas>=0.25->xarray) (2.8.0)
Requirement already satisfied: six>=1.5 in c:\anaconda3\lib\site-packages (from python-dateutil>=2.7.3->pandas>=0.25->xarray) (1.12.0)
Installing collected packages: xarray
Successfully installed xarray-0.16.2

当你的回答包含终端输出时,最好进行格式化。 - Matt
'C:\Program' is not recognized as an internal or external command, operable program or batch file. - The Singularity

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接