Installing the Swampy Python module on Windows

半城伤御伤魂 提交于 2019-11-26 23:39:46

问题


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?


回答1:


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.




回答2:


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.




回答3:


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




回答4:


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.




回答5:


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!




回答6:


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^^



来源:https://stackoverflow.com/questions/5531850/installing-the-swampy-python-module-on-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!