Installing Swampy for python 3 in Windows

≯℡__Kan透↙ 提交于 2019-12-12 19:22:18

问题


I am a beginner python learner using The book 'Think Python' where I have to install module name Swampy. The link provided fro instruction and download has a tar.gz file. I found the python 3 version of the swampy with google search here. All setup tools for modules are under python 3. I am pretty lost, how do i install/use the module?

Thanks


回答1:


You don't have to install Python modules. Just import them. (In fact, swampy is a package, which is basically a collection of modules.)

import swampy

Of course, Python has to know where to import them from. In this case, the simplest thing for you to do is to invoke Python from the directory containing the folder swampy, since the interpreter will first search for modules in the current directory. You can equivalently os.chdir to the directory after invoking Python from anywhere.

Don't worry about setuptools yet.




回答2:


for python 2.7 I go to C:/Python27/Scripts dir and then try to "easy_install " or "pip install ". can be a file. if it does not help: try to unzip downloaded source files and execute "python setup.py install" from command promt




回答3:


The link is correct but the explanation is vague even for an experienced Windows developer. It assumes too much knowledge of the Python installation process IMO.

e.g. "The simplest way to use this code is to unzip it in your home directory, cd into the unzipped directory and work there." What is meant by 'home directory'? Then there is a reference to an 'unzipped directory', which I presume means the home directory. The change of name is confusing.

Nevertheless, say one unzips to C:\Python33\lib\swampy-2.1, and works from there. Whatever this means? I can only presume it means save your code in the swampy 'home directory'. It is not best practice to save your python code in a library directory. I use \dev\python\test\ but then

Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:18:40) [MSC v.1600 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import swampy
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import swampy
ImportError: No module named 'swampy'

However, if the swampy directory is simply renamed to swampy (from swampy-2.1) then all is OK!

>>> import swampy
>>> from swampy.Gui import *
>>> g=Gui()
>>> g.title('Swampy.GUI')
>>> g.mainloop()

FYI this is my path (my dev drive is E: rather C:)

E:\Python33\Lib>path
PATH=E:\Python33\;E:\WINDOWS\system32;E:\WINDOWS;E:\WINDOWS\System32\Wbem;E:\Program Files\Microsoft SQL Server\100\Tool
s\Binn\;E:\Program Files\Microsoft SQL Server\100\DTS\Binn\;E:\WINDOWS\system32\WindowsPowerShell\v1.0;E:\Program Files\
Microsoft\Web Platform Installer\;E:\Program Files\Microchip\xc8\v1.21\bin;E:\Program Files\GtkSharp\2.12\bin

and I don't have a PYTHONPATH environment variable as suggested by other posts.




回答4:


One easy method is by unpacking the contents into a directory of its own in the Python root directory. Then point Python to the location of the module in the file modulepaths.pth (You may need to create this file in the root directory of your python installation.) You can either put the full path or a just a relative path. My modulepaths.pth looks like this with one relative and one full path:

swampy
c:\Python34\arduino


来源:https://stackoverflow.com/questions/12221420/installing-swampy-for-python-3-in-windows

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