简体   繁体   English

在没有命令提示符的情况下安装 Python 模块。

[英]Installing Python modules without command prompt.

I have Python on my school computer, but I would like to install a few modules.我的学校计算机上有 Python,但我想安装一些模块。 How could I get passed this problem.我怎么能通过这个问题。

I installed python packages in school with this.我用这个在学校安装了python包。

open a python shell and write the following:打开一个python shell并编写以下内容:

import pip
pip._internal.main(["install", "--user", <PACKAGE>])

For school computers that don't allow you install libraries via cmd here's a way around it!对于不允许您通过 cmd 安装库的学校计算机,这是一种解决方法!

import pip 

press enter按回车

pip.main(["install", "--user", "Libraryname"]) 

"user" may not be important so only use it if it doesn't work the first time running it “用户”可能并不重要,所以只有在第一次运行它不起作用时才使用它

You can try the following:您可以尝试以下方法:

import subprocess
subprocess.call('pip install X --target=d:\some\folder\with\write\permission', shell=True)

Is a python script that will try to install the package X in some folder that you want.是一个 python 脚本,它将尝试将包 X 安装在您想要的某个文件夹中。 Maybe this way you can do it.也许这样你就可以做到。

I got around this problem by running the following:我通过运行以下命令解决了这个问题:

import os
os.system('pip install --user X')

which did not require admin privileges.这不需要管理员权限。
You may then need to add the packages directory to the path然后,您可能需要将包目录添加到路径

You can also install libraries from powershell if using a windows computer.如果使用 Windows 计算机,您还可以从 powershell 安装库。 First open up IDLE首先打开IDLE

import subprocess
subprocess.call('powershell.exe')

After powershell opens it automatically opens to the python directory. powershell打开后会自动打开python目录。 You want to go back to C: with cd.. .你想回到C:cd.. From there use cd users and cd yourusername.从那里使用 cd users 和 cd yourusername。 It should look like.它应该看起来像。

PS C:/users/your username> 

Set environment with设置环境

$env:path="$env:Path;c:/program files/python310"

Set python310 to python your version (python38, python36, ect.).将 python310 设置为 python 你的版本(python38、python36 等)。 After this you can do a standard pip install.在此之后,您可以进行标准的 pip 安装。

python -m pip install <pythonlibrary>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM