在 Windows 上安装 Swampy Python 模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5531850/
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-09-15 16:32:58  来源:igfitidea点击:

Installing the Swampy Python module on Windows

pythonwindowsswampy

提问by vrfjghrdkrdji

I am trying to install the Swampy moduleon Python, but there is a lot that is unclear in the instructions given on the site and the documentation. I have put the Swampy folder into the site-packages folder of Python 2.7.1, but I don't know how to make the .pth file that will get it installed so that the module can be imported. Can anyone give me instructions on how to make one of these magical .pth files?

我正在尝试在 Python 上安装Swampy 模块,但是站点和文档中给出的说明中有很多不清楚的地方。我已将 Swampy 文件夹放入 Python 2.7.1 的 site-packages 文件夹中,但我不知道如何制作安装它的 .pth 文件,以便可以导入模块。谁能告诉我如何制作这些神奇的 .pth 文件之一?

回答by joaquin

After you unzip your swampy-2.0 folder in the site-packages directory, you only have to create, also in site-packages, a text file called misite.pth(the only important thing here is the .pth extension, you can use whatever filename you like). The .pth file should simply contain one line: the name of your folder ('swampy-2.0'). That is all.

在 site-packages 目录中解压 swampy-2.0 文件夹后,您只需要在 site-packages 中创建一个名为的文本文件misite.pth(这里唯一重要的是 .pth 扩展名,您可以使用任何您喜欢的文件名)。.pth 文件应该只包含一行:文件夹的名称('swampy-2.0')。就这些。

Python search for files with the extension .pth and put the directory names in these files in the module search path. A path file can contain the name of one or several folders, one per line.

Python 搜索扩展名为 .pth 的文件,并将这些文件中的目录名放在模块搜索路径中。一个路径文件可以包含一个或多个文件夹的名称,每行一个。

回答by Isaac Sutherland

Put your swampy-2.0 directory in the PYTHONPATH environment variable. Once you do that, you can just open a python shell and import the swampy classes just as shown in the Think Python book. On my Windows machine, I extracted the swampy-2.0 source files to my Downloads folder -- I didn't put it in the site-packages directory at all.

将 swampy-2.0 目录放在 PYTHONPATH 环境变量中。一旦你这样做了,你就可以打开一个 python shell 并导入 swampy 类,就像 Think Python 书中所示。在我的 Windows 机器上,我将 swampy-2.0 源文件解压缩到我的下载文件夹——我根本没有把它放在 site-packages 目录中。

回答by mturilli

If you installed setuptools, then you can install Swampy with: easy_install swampy.

如果您安装了setuptools,那么您可以使用以下命令安装 Swampy:easy_install swampy

回答by AguNnamdi

Now you're ready to install a package. There's lots to chose from but we'll start here...

现在您已准备好安装软件包。有很多选择,但我们将从这里开始......

Download swampy at http://pypi.python.org/pypi/swampy/2.1.1This is a swampy-2.1.1.tar.gz file, which in Windows language means it is a strange and otherworldly kind of zip file.

http://pypi.python.org/pypi/swampy/2.1.1下载 swampy 这是一个 swampy-2.1.1.tar.gz 文件,在 Windows 语言中,这意味着它是一种奇怪且超凡脱俗的 zip 文件。

To open the *tar.gz file, download PeaZip for Windows http://peazip.org/Use PeaZip to extract (uncompress / unzip) swampy-2.1.1.tar.gz into your Download directory. You should end up with something similar to this: C:\Users\Nnamdi\Downloads\swampy-2.1.1\

要打开 *tar.gz 文件,请下载适用于 Windows 的 PeaZip http://peazip.org/使用 PeaZip 将 swampy-2.1.1.tar.gz 解压缩(解压缩/解压缩)到您的下载目录中。你应该得到类似的结果:C:\Users\Nnamdi\Downloads\swampy-2.1.1\

Go back to your Command Prompt window or open a new one. You'll need to change directories in the command line to your user directory in the computer.

返回命令提示符窗口或打开一个新窗口。您需要将命令行中的目录更改为计算机中的用户目录。

When you start, your command line should look something like this: c:\Users\Nnamdi> You want to get into the swampy-2.1.1 directory, so at the command prompt type this: cd downloads\swampy-2.1.1 or the complete path: cd c:\Users\Nnamdi\Downloads\swampy-2.1.1 Your prompt will change from this c:\Users\Nnamdi> to this c:\Users\Nnamdi\Downloads\swampy-2.1.1>

启动时,您的命令行应如下所示: c:\Users\Nnamdi> 您想进入 swampy-2.1.1 目录,因此在命令提示符下键入: cd downloads\swampy-2.1.1 或完整路径: cd c:\Users\Nnamdi\Downloads\swampy-2.1.1 你的提示将从这个 c:\Users\Nnamdi> 变成这个 c:\Users\Nnamdi\Downloads\swampy-2.1.1>

Now for the fun part. Inside that swampy directory there is a file called setup.py. We're going to install that into the Python universe. Type this into the Command Prompt :

现在是有趣的部分。在那个沼泽目录中有一个名为 setup.py 的文件。我们将把它安装到 Python 世界中。在命令提示符中输入:

python setup.py install

python setup.py 安装

Now open IDLE (Start > All Programs > Python 2.7 > IDLE (Python GUI)) and type the following:

现在打开 IDLE(开始 > 所有程序 > Python 2.7 > IDLE (Python GUI))并输入以下内容:

import swampy.TurtleWorld See all that nothing that happens? That's your sign of success. Congratulations. You've just installed and imported your first package for Python on Windows 7. Repeat as needed.

import swampy.TurtleWorld 看到什么都没有发生吗?那是你成功的标志。恭喜。您刚刚在 Windows 7 上安装并导入了第一个 Python 包。根据需要重复。

回答by Bee Dev

Installing python packages on windows might be a little bit tricky. You could learn more about running python on windows here https://docs.python.org/2/faq/windows.html. This walk through will hopefully help you install swampy package into python.

在 windows 上安装 python 包可能有点棘手。您可以在https://docs.python.org/2/faq/windows.html上了解有关在 Windows 上运行 python 的更多信息。本演练有望帮助您将 swampy 包安装到 python 中。

Set PATH

设置路径

PATH is a windows enviroment variable that points to an excutable file. When you installed python you must have created a path. If you followed the instructions of the book your PATH value is "C:\Python and is named Python. Check your path by

PATH 是指向可执行文件的 Windows 环境变量。安装 python 时,您必须创建一个路径。如果您按照本书的说明进行操作,则您的 PATH 值是“C:\Python 并命名为 Python。检查您的路径

Right click Computer Choose Advanced System Settings Choose Environment Variables Double click the PATH variable You should see something like C:\Python

右键单击计算机 选择高级系统设置 选择环境变量 双击 PATH 变量 您应该看到类似 C:\Python 的内容

You can learn more about installing python on windows 'as well as setting PATH' here https://docs.python.org/2/using/windows.html

您可以在此处了解有关在 Windows 上安装 python 以及设置 PATH 的更多信息https://docs.python.org/2/using/windows.html

Download and extract package

下载并解压包

Second, you need to download your package, in this case the module you are downloading is called swampy. The packages you download are in .gz extention which is equivilant to .zip extenstions which are compressed files that need to be uncompressed. You can choose from a variaty of applications available online to unzip the .gz files.

其次,您需要下载您的软件包,在这种情况下,您正在下载的模块称为 swampy。您下载的包在 .gz 扩展名中,与 .zip 扩展名相同,后者是需要解压缩的压缩文件。您可以从各种在线应用程序中进行选择,以解压缩 .gz 文件。

Install Package to Python

安装包到 Python

The next step is to install the package to python. To do this you have to use the Command Prompt.

下一步是将包安装到python。为此,您必须使用命令提示符。

Open the Command Prompt by typing cmd in search then press enter Change the command directory to make it point to the unzipped files of the installed package using "cd C:\Users\exampleFile\swampy-2.1.7" Install the package to python by typing " python setup.py install" In the last step you are pointing to the setup file that is included in the folder pointed by the directory you set in step 2. Make sure you printed out the full directory.

通过在搜索中键入 cmd 来打开命令提示符,然后按 Enter 更改命令目录以使其指向使用“cd C:\Users\exampleFile\swampy-2.1.7”的已安装包的解压缩文件 将包安装到 python键入“python setup.py install” 在最后一步中,您指向的安装文件包含在您在步骤 2 中设置的目录所指向的文件夹中。确保打印出完整的目录。

Import module

导入模块

Finally, after you have done the previous steps now you can download the module inside the python IDLE. Just open the IDLE and print " from swampy.Turtle import *

最后,在您完成前面的步骤之后,您现在可以在 python IDLE 中下载模块。只需打开 IDLE 并打印“ from swampy.Turtle import *

If the interpreter does not show an error , then you have installed swampy

如果解释器没有显示错误,那么您已经安装了swampy

Note: Module name is case sensitive using the above statement in python IDLE.

注意:模块名称区分大小写,在 python IDLE 中使用上述语句。

Hope this helped, cheers!

希望这有帮助,干杯!

回答by asunnysunday

I also encountered this problem.

我也遇到了这个问题。

joaquin's method works like charm, and the following is another solution.

joaquin 的方法很有魅力,下面是另一种解决方案。

  1. You don't need to create a .pth file.
  1. 您不需要创建 .pth 文件。

2.Just put all files in the directory .../Python 2.7.1/Lib/site-packages(... means the location where you installed Python) note that you shouldn't put the "swampy-2.0" FOLDER in .../Python 2.7.1/Lib/site-packages, but put all FILESin the "swampy-2.0" FOLDER in .../Python 2.7.1/Lib/site-packages(that is: all the .py files are in the path .../Python 2.7.1/Lib/site-packages, not .../Python 2.7.1/Lib/site-packages/swampy-2.0.

2.把所有文件放在目录.../Python 2.7.1/Lib/site-packages(...表示你安装Python的位置) 注意不要把“swampy-2.0”文件夹放在.../Python 2.7.1/Lib/site-packages,但将所有文件放在 .../Python 2.7.1/Lib/site-packages中的“swampy-2.0”文件夹中(即:所有 .py文件位于路径 .../Python 2.7.1/Lib/site-packages 中,而不是 .../Python 2.7.1/Lib/site-packages/swampy-2.0。

This worked for me(I didn't create a .pth file), try it^^

这对我有用(我没有创建 .pth 文件),试试吧^^