Error importing Zelle's graphics.py package - python

I am working though Zelle's Python book (Python 2.7.5, Canopy Express, Windows 7). For Chapter 5 you need to install his graphics package, graphics.py. I downloaded the current version, put it in the C:\Python27\Lib\site-packages folder and made sure the file has the '.py' extension, but when I type >>import graphics I get the following error in both Canopy and IDLE:
ImportError
Traceback (most recent call last)
<ipython-input-1-e6fd1288a7fc> in <module> ()
----> 1 import graphics
ImportError: No module named graphics
To the best of my knowledge I've followed the instructions and hints on the website and here in StackOverflow, but I'm flummoxed. Any suggestions? I like the Zelle book but I'm not sure how much use it will be from this point on without the graphics package - from just skimming it seems like the majority of the examples and exercises use it. Thanks.

It took a while, but I got it working. Enthought Canopy uses its own (virtual) environments, so you need to put Zelle's graphics package there, not in the system library. I had success by placing graphics in Enthought's top level directory, which you can determine in the interpreter:
>> import site
>> site.getpackages()[0]
I copied the graphics package there, without the .py extension, fired up Canopy and I was off and running. Thanks to everyone who has posted, in various places, tips on importing - eventually it made sense! By the way,
>> site.getpackages()
will give you all site package directories, but I only needed the first.

Related

Pandas Installed For All Python Versions But Module Can't Be Found

I am trying to modify an AI for a game on the steam store. The AI communicates through the game with the use of a mod called the communication mod. The AI is made using a python project. The package I am trying to modify is https://github.com/ForgottenArbiter/spirecomm and the mod is https://github.com/ForgottenArbiter/CommunicationMod.
I want to add the pandas package and the job lib package as imports so I can use a model I have made for the AI. When I try to run the game + mod after adding the pandas and joblib packages as imports I get this error in the error log.
Traceback (most recent call last):
File "/Users/ross/downloads/spirecomm-master/main.py", line 6, in <module>
from spirecomm.ai.agent import SimpleAgent
File "/Users/ross/Downloads/spirecomm-master/spirecomm/ai/agent.py", line 10, in <module>
import pandas as pd
ModuleNotFoundError: No module named 'pandas'
This issue only happens when the game is running and the mod tries to run. if I just run the file in terminal it is able to compile/run and send the ready signal
I have checked that I have these modules installed and it is installed. I am on an M1 Mac and I have several different versions of python installed but I have checked them all and it is installed for each of them. I have also opened the python package using pycharm and added pandas and joblib to the python interpreter as a package.
Another thing I have tried is modifying the setup.py file to say that pandas and joblib are required. I then ran it again but I am not sure if this had any effect because I have already run it before.
There is limited help that can be provided without knowing the framework that you are is using but hopefully this will give you some starting points to help.
If you are getting a "No module named 'pandas'" error, it is because you have imported pandas in your code but your python interpreter cannot find it. There are two major reasons this will happen, either it is not installed (which you say has definitely happened) or it is not in the location the interpreter expects (most likely).
The first thing you can do is make sure the pandas install is in the PYTHONPATH. To do this look at Permanently add a directory to PYTHONPATH?.
Secondly, you say you have several versions of python and have installed the module for all versions but you most likely have several instances of at least one version. Many IDEs, such as PyCharm, create a virtual environment when you create a new project and place in it a new instance of python interpreter, or more accurately a link to one version of python. Within this virtual environment, the IDE then loads the modules it has been told to load and thus makes them available for import to the code using that particular environment.
In your case I suspect you may be using a virtual environment that has not had pandas loaded into it. You need to investigate your IDEs documentation if you do not know how to load it. Alternatively you can instruct the IDE to use a different virtual environment (one that does have pandas loaded) - again search documentation for how to do this.
Finally, if all else fails, you can specifically tell your code where to look for the module using the sys.path.append command in your code.
import sys
sys.path.append('/your/pandas/module/path')
import pandas

How do I run the OpenGrasp Robot Editor with Blender on Mac OS X?

I'm using Mountain Lion at the moment.
I've installed Blender (because it's a dependency of OpenGrasp), and downloaded OpenGrasp. However, I try to load the robot editor up and I get this:
$ python GraspRobotEditor.py
Traceback (most recent call last):
File "GraspRobotEditor.py", line 34, in <module>
import Blender
ImportError: No module named Blender
How do I point Python to the Blender python interface? the Getting Started guide doesn't instruct you much here.
(I'm sure this is a trivial problem to solve but I'd like to see this documented on StackOverflow anyway.)
From the error you it can't find the python module Blender which represents the python hook to Blender. So there could be a few This could be any number of reasons to do with your setup.
The first is that the Blender module is runtime generated whileBlender is running. The specific 'Blender' module used is part of the Blender 2.4x series. According to the link you provided there, they mention porting to newer versions but checking their snv the code is definitely written for 2.49.
Blender 2.49b was the last stable release - http://download.blender.org/release/ Ensure you are using that.
The next thing is whether it can be run via the the Run Script command
TL:DR
Start up blender
Switch to the text workspace
Open the script and see if it can be run directly.
If not you will need to install the folder to the Blender modules directory of your install and then try running it.
Edit: Was looking at into the SVN some more and there does appear to be a version 2 for blender 2.5+ which can be put into a zip file and installed via the add-on installer. According to the bl_info it was build for 2.58 but what support level you would need to try out yourself.

Trouble importing Python modules on Ninja IDE

I have been trying to import modules into Ninja IDE for python. These are modules that I have working on the terminal (numpy, scipy, scitools, matplotlib, and mpl_toolkits), but will not run correctly in Ninja.
First I was only getting the message No module named ____. I checked sys.path and found that the path was within the application
/Applications/Ninja IDE.app/Contents/Resources/lib/python2.7 was a typical path. I tried changing the path,but it doesn't seem to do anything to sys.path even after restarting the ide.
But I wanted the path to refer to where the modules are stored (which is /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages). I was able to get numpy and scipy to work as well as parts of mpl_toolkits by adding the contents of my path to the folders that sys.path gave. However, I still can't get fully functioning modules within the ninja ide interpreter. I'll give some examples below of what happens when I import certain modules.
import matplotlib.pyplot
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Applications/Ninja IDE.app/Contents/Resources/lib/python2.7/matplotlib/__init__.py", line 106, in <module>
ImportError: No module named sysconfig
import mpl_toolkits
from mpl_toolkits.mplot3d import axes3d
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Applications/Ninja IDE.app/Contents/Resources/lib/python2.7/mpl_toolkits/mplot3d/__init__.py", line 1, in <module>
File "/Applications/Ninja IDE.app/Contents/Resources/lib/python2.7/mpl_toolkits/mplot3d/axes3d.py", line 14, in <module>
File "/Applications/Ninja IDE.app/Contents/Resources/lib/python2.7/matplotlib/__init__.py", line 106, in <module>
ImportError: No module named sysconfig
Thanks for the help. I apologize, I am very new to programming, but I did put in about a day and a half of research before posting here.
That's strange as the sysconfig module is a part of Python 2.7 standard library.
Are you sure that Ninja is using the right Python version? Try running:
import sys
print sys.version_info
from Ninja, to see which Python version it is actually using.
I know this question is a few months old, but I wanted to post my solution in case others find it useful. I had a very similar problem, and had a lot of trouble finding a quick workable solution anywhere.
My somewhat roundabout solution was to simply create a virtualenv folder with the version of numpy I wanted, and then pointed the "virtualenv" property for NinjaIDE project to that folder. I restarted NinjaIDE and boom, instantly worked.
To set the virtualenv property for your project via the GUI, go to the Project menu:
Project > Open Project Properties > Project Execution,
and you should see a variable called "Virtualenv Folder". Point that to the folder for your virtualenv, and it should work. (May need to restart NinjaIDE.) This worked for me, NinjaIDE version 2.2 under Ubuntu 12.04.
One quick note: I actually didn't use virtualenv exactly -- I had to use a "conda env," since I am using the Anaconda distribution, and apparently it is not well-tested with virtualenv yet. (I actually got a warning when I went to easy_install virtualenv. Hadn't seen that before.)
Either way, this stackoverflow question has some nice pointers to virtualenv tutorials: Comprehensive beginner's virtualenv tutorial?
Good luck!
I was having a similar problem trying to import a module from /home/paul/lib/python using the console of the Ninja-IDE. I found out that /home/paul/lib/python didn't appear in syspath when checking in the console of the Ninja-IDE. But it did in the terminal!
By starting the Ninja-IDE from the terminal, /home/paul/lib/python was in syspath when checking in the console of the Ninja-IDE. I was now able to import the module I needed.
I hope this might be of some help. If not to ebris1 than maybe to others.

Error Importing Graphics Python

I'm typing at the console
from graphics import *
and I get this error
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
from graphics import *
ImportError: No module named graphics
I think your question comes from trying to work through Python Programming by John Zelle, with a Macintosh.
The first 4 chapters are great. But in chapter 5, where I tended to get stuck, he introduces Objects. The way he does that is kind of interesting. He has created a python module which he calls “graphics.py” which you can download from his website.
This module (I’ve attached a link to it below) is a python program written by Mr. Zelle. It creates the tools for making very simple shapes and getting used to the basic concepts with graphics and it also serves as a more tangible way of introducing Objects.
However I was confused, it took me a while to realize that “graphics.py” was a pedagogical program Mr. Zelle created, and not something that comes bundled with MacPython. This confusion stems from the fact that the programs in Chapter 5 all begin with “import graphics” which looks very similar to the “import math” command at the beginning of every program in the 3rd chapter.
The key difference is that “import math” imports the standard mathematics library that came pre-bundled with MacPython. But “import graphics” refers to John Zelle’s own “graphics.py” module, which you have to download and instal first.
It took me a while to figure that out….
Then once I did, I went to his website, copied the program from this website:
http://mcsp.wartburg.edu/zelle/python/graphics.py
...into IDLE and then saved it as graphics.py
This is where it got maddening...
On Windows if you just put the graphics.py file in the same folder as Python, it can find the file and use it without a problem.
Here is what the book said, that made me feel so crazy:
“To use the graphics module (graphics.py) you need to place this file where Python can locate it. >One simple approach is to put it in the same folder where you keep your Python programs. Starting >Python in this folder will also let you import the graphics library to experiment interactively.
Alternatively, you can place the graphics.py file in a system-wide directory so that it is >available for import no matter what directory Python starts in. The standard directory for placing >local additions to Python is the site-packages directory. On my Windows installation, the complete >path to the folder is:
C:\Python23\Lib\site-packages
On my Linux system, the file resides in:
/usr/local/bin/lib/python2.3/site-packages."
On a windows OS, all that you have to do is go to Python.org and download Python for Windows and put that graphics.py file in the main folder, and boom, you’re golden, NOT SO FOR MACINTOSH!!!!
2 years ago, this is where I got totally stuck, because I had no idea about site paths, or directories; I just pointed and clicked; I didn’t know about the Unix system underneath the Macintosh Aqua GUI.
And the book gives no instructions for what to do if you have a Macintosh, and I hit a wall.
But when I went at it again a few weeks ago, those directories made more sense to me, because I spent the spring and summer playing with a guidebook to using the UNIX command shell on my Mac.
So I realized that my problem had nothing to do with Tkinter, It was just that graphics.py needed to be in the right directory. I couldn’t just put it in the folder next to IDLE as I could on a Windows machine. I needed to find the right directory.
Since OSX is built on a UNIX base, I thought that the file path might be the same as Linux. Sadly, there was no “local”, “bin” after the “user” directory. But its not quite the same in OSX.
Instead you can use IDLE itself to find out which path directories it uses.
You type this:
import sys
print sys.path
and BOOM, it spits out a whole bunch of directories, confusingly formatted like this
['', '/Users/jamesbarnard/Documents', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages’,
'/Library/Python/2.7/site-packages’]
But when I looked closer I noticed the directory “site-packages” which looked a lot like the “site-packages” on the Linux and Windows command lines.
So I pulled out that directory chain
['', '/Users/jamesbarnard/Documents', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload’,
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages', ‘
/Library/Python/2.7/site-packages’]
Then using the UNIX shell I followed it down, and then I did the same thing in the Aqua interface.
And there, buried 8 levels down in the directory, amidst hundreds of other files, I placed my graphics.py file.
Then I went back into IDLE, typed in “import graphics”
AND IT WORKED!!
If you are having this problem. I hope this solution saves you my headache.
did you follow the instructions to install the graphics module and is it in your pythonpath?
Type how to install graphics.py in Google.
http://www.google.co.in/search?sourceid=chrome&ie=UTF-8&q=how+tooinstall+gaphics.py#sclient=psy-ab&hl=en&source=hp&q=how+to+install+gaphics.py&pbx=1&oq=how+to+install+gaphics.py&aq=f&aqi=&aql=&gs_sm=s&gs_upl=0l0l0l24645l0l0l0l0l0l0l0l0ll0l0&bav=on.2,or.r_gc.r_pw.r_cp.,cf.osb&fp=344adf6de4d60025&biw=1366&bih=600
Click on the third link
http://mcsp.wartburg.edu/zelle/python/graphics.py
Copy that file which got downloaded to your lib folder in Python32 in C drive.
The error will not occur now.
Short cut to installing graphics.py via command line and/or terminal window. run the following command in admin rights in windows.
this will allow you to import graphics
pip3 install --user http://bit.ly/csc161graphics
ps. Im running python 3.6.2 on Atom. Hope this helps some.
Perhaps you forgot to run python setup.py -install after downloading the module.
You can also put graphics.py in the same folder where you started the python shell.
http://mcsp.wartburg.edu/zelle/python/graphics.py
I recently had this issue where I typed (and pasting the code into the interpreter did not work either) 'import graphics' into the interpreter and the error I got was:
Traceback (most recent call last):
File "", line 1, in
from graphics import *
ImportError: No module named graphics
I took the following steps to fix the error:
-Go to: http://mcsp.wartburg.edu/zelle/python/
-Right click on the link 'graphics.py and click 'save target as'
-save in the directory 'Python33', along with the 'chaos.py' file. This step is important that you do not save it in other locations (it may work if you save it in other locations I decided to save it in this location).
Hope this helps.

maya2008 win32api 64 bit python

How is it possible to run import win32api successfully on a 64bit maya version 2008?
The following error occurs:
Error: No module named win32api
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named win32api
I need to get mouse cursor position in python so that I can place window exactly in that position. Is there any other way to get it?
Best regards,
kNish
Maya uses its own Python installation. You need to add the path where pywin32 is installed by one way or another ... you can create a .pth file in
C:\Program
Files\Autodesk\Maya2009\Python\Lib\site-packages\
Also, like Adam pointed out, make sure you have the 64 bit pywin32 installed.
Here's an article talking about this subject:
http://www.rtrowbridge.com/blog/2008/11/27/maya-python-import-scripts/
Edit:
Yeah indeed I think they don't provide PyWin32 for Python25 x64:
Available for AMD64 versions of
Windows for Python 2.6 and later
(support for Python 2.5 is just too
hard, sorry). Lots of help from
Roger, Steve Yin and Sidnei da
Silva.
http://sourceforge.net/project/shownotes.php?release_id=603349

Categories