在 Windows 上使用 IDLE 安装 python 模块/包

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27409192/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 01:46:09  来源:igfitidea点击:

Install python modules/package using IDLE on Windows

pythonpython-2.7python-3.x

提问by PalashV

I have a python script and begins as (just a part of it) -

我有一个 python 脚本并以(只是它的一部分)开始 -

import requests
from bs4 import BeautifulSoup
import itertools
import io
import re
import smtplib, os

Now, when I run it, it says missing requests module.

现在,当我运行它时,它说缺少请求模块。

I've downloaded & installed 3 versions of Python from python.org, but still it seems that the packages are not installed. Can anyone tell me how to install modules using IDLE on Windows 7.

我已经从 python.org 下载并安装了 3 个版本的 Python,但似乎仍然没有安装这些软件包。谁能告诉我如何在 Windows 7 上使用 IDLE 安装模块。

Versions I have - 2.7.8, 3.3.5, 3.4.2.

我拥有的版本 - 2.7.8、3.3.5、3.4.2。

采纳答案by Alibi Ghazi

you can use pip(a package manager for python) to install dependencies . check this link : https://pip.pypa.io/en/latest/installing.html

您可以使用 pip(python 的包管理器)来安装依赖项。检查此链接:https: //pip.pypa.io/en/latest/installing.html

回答by Jo?o Paulo

You can find Windows binaries for Python packages here:

您可以在此处找到 Python 包的 Windows 二进制文件:

http://www.lfd.uci.edu/~gohlke/pythonlibs/

http://www.lfd.uci.edu/~gohlke/pythonlibs/

It's just install.

这只是安装。



Or you can use pip:

或者你可以使用 pip:

https://pip.pypa.io/en/latest/installing.html

https://pip.pypa.io/en/latest/installing.html

Add pip to the system path and run commands on cmd, example:

将pip添加到系统路径并在cmd上运行命令,例如:

pip install numpy

More info to install pip:

安装 pip 的更多信息:

How do I install pip on Windows?

如何在 Windows 上安装 pip?



回答by Imtiaz Chowhdhury

Open command prompt and type

打开命令提示符并键入

C:\Users\Imtiaz Chowdhury\Scripts\pip

install requests here.

在这里安装请求。

C:\users\Imtiaz Chowdhuryis my file path and requestsis my module name; you can specify yours.

C:\users\Imtiaz Chowdhury是我的文件路径,requests是我的模块名称;你可以指定你的。

Ensure that you have pip.exefile in the specified scripts folder.

确保您pip.exe在指定的脚本文件夹中有文件。

回答by TheHolyDarkness

Under present versions of Python (version 3.4 or above), do the following:

在当前版本的 Python(3.4 或更高版本)下,执行以下操作:

Windows

视窗

At the command prompt enter

在命令提示符下输入

py -3 -m pip install BeautifulSoup4

Linux

Linux

At the terminal enter

在终端输入

sudo python3 -m pip install BeautifulSoup4

回答by NDM

In Windows you should, like in Linux, use the command prompt to install your packages using pip. However, for this to work the Python executable must be in the system path. Also, all your different versions of Python need the packages installed individually.

在 Windows 中,您应该像在 Linux 中一样,使用命令提示符使用 pip 安装您的软件包。但是,要使其工作,Python 可执行文件必须位于系统路径中。此外,所有不同版本的 Python 都需要单独安装软件包。

The issue is that in the installations of all the different versions of Python, all of them have a executable called python.exe i.e. same name!

问题是在所有不同版本的 Python 的安装中,它们都有一个名为 python.exe 的可执行文件,即同名!

Thus, you need to rename them, for example, to python27, python33, etc. to access them individually. By renaming them and calling "pythonXX" in cmd prompt this can be done, otherwise, cmd will just take the first instance of python.exe in the system path when "python" is called in cmd.

因此,您需要将它们重命名,例如,重命名为 python27、python33 等,以便单独访问它们。通过重命名它们并在 cmd 提示符下调用“pythonXX”可以做到这一点,否则,当在 cmd 中调用“python”时,cmd 将只获取系统路径中 python.exe 的第一个实例。

This is particularly problematic if Anaconda2 is also installed because all packages will just there. Once you are able to run your different versions of Python from the command line you should be able to install packages correctly using pip.

如果还安装了 Anaconda2,这尤其成问题,因为所有软件包都在那里。一旦您能够从命令行运行不同版本的 Python,您就应该能够使用 pip 正确安装软件包。

In summary:

总之:

  • Rename python.exe to pythonXX.exe
  • Add the folder in which pythonXX.exe is located to the system path (see below)
  • Start cmd prompt and write "pythonXX -m pip install -U pip" - This command updates pip. If it dosen't work restart the computer to update path and try again.
  • Now you should be able to install packages into the correct versions using pip.
  • Note that you should write e.g. "pythonXX -m pip install -U scikit-learn" to install your libraty.
  • 将 python.exe 重命名为 pythonXX.exe
  • 将pythonXX.exe所在的文件夹添加到系统路径(见下)
  • 启动 cmd 提示符并写入“pythonXX -m pip install -U pip” - 此命令更新 pip。如果它不起作用,请重新启动计算机以更新路径并重试。
  • 现在您应该能够使用 pip 将软件包安装到正确的版本中。
  • 请注意,您应该编写例如“pythonXX -m pip install -U scikit-learn”来安装您的库。

Once the packages are installed into the right folders, they should also be available from IDLE and you are ready to go.

将软件包安装到正确的文件夹中后,它们也应该可以从 IDLE 获得,您就可以开始使用了。

To access system path in Windows

在 Windows 中访问系统路径

  1. Go to Control Panel
  2. Select “System” from the context menu.
  3. Click “Advanced system settings”
  4. Go to the “Advanced” tab
  5. Click “Environment Variables…”
  6. Click variable called “Path” and click “Edit…”
  7. Click “New”
  8. Enter the path to the folder containing the executable you want on your PATH. For example, to add python33.exe, add: "C:\Python33\" or what your path to python33.exe is.
  1. 进入控制面板
  2. 从上下文菜单中选择“系统”。
  3. 点击“高级系统设置”
  4. 转到“高级”选项卡
  5. 点击“环境变量...”
  6. 单击名为“路径”的变量,然后单击“编辑...”
  7. 点击“新建”
  8. 在 PATH 中输入包含所需可执行文件的文件夹的路径。例如,要添加 python33.exe,请添加:“C:\Python33\”或 python33.exe 的路径是什么。

回答by Joel Jogy

This is how I would do it.

这就是我要做的。

  1. Right-click command prompt from Start, and run it as administrator
  2. Write the command: cd C://Python27/Scripts
  3. Hit enter
  4. Write the pip install command: pip install requests
  5. Hit enter
  6. Voila it's installed now.
  1. 从开始右键单击命令提示符,然后以管理员身份运行它
  2. 编写命令: cd C://Python27/Scripts
  3. 按回车
  4. 编写 pip install 命令: pip install requests
  5. 按回车
  6. 瞧,它现在已经安装好了。