I'm following the tutorial "Think Python" and I'm supposed to install the package called swampy. I'm running python 2.7.3 although I also have python 3 installed. I extracted the package and placed it in site-packages:
C:\Python27\Lib\site-packages\swampy-2.1.1
C:\Python31\Lib\site-packages\swampy-2.1.1
But when i try to import a module from it within python:
import swampy.TurtleWorld
I just get no module named swampy.TurtleWorld.
I'd really appreciate it if someone could help me out, here's a link to the lesson if that helps:
http://www.greenteapress.com/thinkpython/html/thinkpython005.html
This is caused by the fact that the version of Python you're running your script with is not configured to search for modules where you've installed them. This happens when you use the wrong installation of pip to install packages.
The ImportError is raised when an import statement has trouble successfully importing the specified module. Typically, such a problem is due to an invalid or incorrect path, which will raise a ModuleNotFoundError in Python 3.6 and newer versions.
The import error can be caused by limits set by the program using the file or the amount of available memory on the system. If your import fails because of file size issues, you need to go back and break the file up into smaller files which will enable it to successfully upload. 2.
To import the module, you simply have to put the name of the ROS package where the module was installed, followed by the name of the file. That's it!
If anyone else is having trouble with this on Windows, I just added my sites-package directory to my PATH variable and it worked like any normal module import.
C:\Python34\Lib\site-packages
Hope it helps.
I extracted the package and placed it in site-packages:
No, that's the wrong way of "installing" a package. Python packages come with a setup.py
script that should be used to install them. Simply do:
python setup.py install
And the module will be installed correctly in the site-packages of the python interpreter you are using. If you want to install it for a specific python version use python2
/python3
instead of python
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With