在 Windows 上安装 Swampy Python 模块

发布于 2024-10-29 05:58:01 字数 253 浏览 1 评论 0原文

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

I am trying to install the Swampy module on 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

冰雪梦之恋 2024-11-05 05:58:01

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

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

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.

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.

酒解孤独 2024-11-05 05:58:01

将 swampy-2.0 目录放入 PYTHONPATH 环境变量中。完成此操作后,您只需打开 python shell 并导入 swampy 类,如 Think Python 书中所示。在我的 Windows 计算机上,我将 sampy-2.0 源文件提取到我的 Downloads 文件夹中——我根本没有将其放在 site-packages 目录中。

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.

以可爱出名 2024-11-05 05:58:01

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

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

淡莣 2024-11-05 05:58:01

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

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

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

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

开始时,您的命令行应如下所示:
c:\Users\Nnamdi>
您想要进入 swampy-2.1.1 目录,因此在命令提示符下键入:
cd 下载\swampy-2.1.1
或完整路径:
cd c:\Users\Nnamdi\Downloads\swampy-2.1.1
您的提示将从此改变
c:\Users\Nnamdi>
对此
c:\Users\Nnamdi\Downloads\swampy-2.1.1>

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

python setup.py install

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

<块引用>
<块引用>

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


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.1
This is a swampy-2.1.1.tar.gz file, which in Windows language means it is a strange and otherworldly kind of zip file.

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\

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>

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 :

python setup.py install

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

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.

深爱成瘾 2024-11-05 05:58:01

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

设置PATH

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

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

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

下载并解压包

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

将包安装到 Python

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

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

导入模块

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

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

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

希望这有帮助,干杯!

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.

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

Right click Computer
Choose Advanced System Settings
Choose Environment Variables
Double click the PATH variable
You should see something like 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

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.

Install Package to Python

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

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.

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 *

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

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

Hope this helped, cheers!

养猫人 2024-11-05 05:58:01

我也遇到了这个问题。

华金的方法就像魅力一样,下面是另一种解决方案。

  1. 您不需要创建 .pth 文件。

2.只需将所有文件放入目录.../Python 2.7.1/Lib/site-packages(...表示你安装Python的位置)
请注意,您不应将“swampy-2.0”文件夹放入 .../Python 2.7.1/Lib/site-packages 中,而应将所有文件放入“swampy-2.0”文件夹中.../Python 2.7.1/Lib/site-packages(即:所有 .py 文件都在路径 .../Python 2.7.1/Lib/site-packages 中,而不是 .../Python 2.7。 1/Lib/site-packages/swampy-2.0。

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

I also encountered this problem.

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

  1. You don't need to create a .pth file.

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 FILES in 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.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文