I had a file called baseFunctions.py which I changed to elementFunctions.py. Importing elementFunctions with parsePeaksMzML.py gave me weird print statements, especially because I did not have any print statements in elementFunctions.py. Stepping through the code with Eclipses debugger showed instead of doing
import elementFunctions
as it said in the parsePeaksMzML.py, it actually did
import baseFunctions
I thought there was some weird mix-up with the renaming, so I copied all the code from elementFunctions.py, deleted the file, made a new file and pasted in all the code in the new file. Still I got the same weird errors. Looking in the folder I still had the baseFunctions.pyc, so I deleted that. Rerunning the code gave me:
Traceback (most recent call last):
File "/homes/ndeklein/workspace/MS/Trunk/PyMS_dev/pyMS/test/test_parsePeaksMzML.py", line 25, in <module>
import parsePeaksMzML
File "/homes/ndeklein/workspace/MS/Trunk/PyMS_dev/pyMS/test/parsePeaksMzML.py", line 12, in <module>
import elementFunctions
ImportError: No module named baseFunctions
Somehow import elementFunctions points to import baseFunctions (I have no clue why) and deleting and remaking elementFunctions.py has no effect. I can't find anything like this searching on google or stack overflow, so I'm kind of stumped here.
I suspect it to be a problem with eclipse, but I'm not sure.
edit:
What makes it even stranger, I get the error when I import parsePeaksMzML.py from
test_parsePeaksMzML.py, but not when I run parsePeaksMzML.py directly.
edit2:
Running from the commandline gives the same error:
-bash-3.2$ python test_parsePeaksMzML.py
Traceback (most recent call last):
File "test_parsePeaksMzML.py", line 26, in <module>
import parsePeaksMzML
File "/homes/ndeklein/workspace/MS/Trunk/PyMS_dev/pyMS/test/parsePeaksMzML.py", line 12, in <module>
ImportError: No module named baseFunctions
-bash-3.2$
If you changed the name of a file, probably you have some old .pyc lingering in your workspace. I'm assuming you're using the PyDev plug-in in Eclipse; I haven't used it in a while, but you should be able to do a Project -> Clean. If that doesn't help, try manually clearing all of the .pyc files in your workspace.
The symptoms you describe are very strange, so I'm not 100% sure what the problem is. Regardless, trying cleaning your workspace and let us know how things progress from there.
Do try a blanket delete of all .pyc files and see if that clears it up. If not, here are a few possibilities:
Your $PYTHONPATH points to different source than you expect. (Though this would likely not be the entire explanation.)
Code within elementFunctions/__init__.py is trying to import baseFunctions.
Code somewhere is using an exec statement to do imports, or using the built-in __import__ function to dynamically import baseFunctions (which might make the source of the directive difficult to hunt down).
Related
I want to make the python script into Windows executable with py2exe. I did not miss MSVCP90.dll and the Feiwings.py(the file that I use for transforming) and setup.py are under the same path. Doing those things under command window, everything works fine, the last lines of the traceback here are:
**binary dependencies****
your executable(s) also depend on these dlls which are not included. You may or may not need to distribute them.
Make sure you have the license if you distribute any of them, and make sure you don't distribute files belonging to the operating system.
USER32.dll -C:\WINDOWS\system32\USER32.dll
SHELL32.dll -C:\WINDOWS\system32\SHELL32.dll
ADVAPI32.dll -C:\WINDOWS\system32\ADVAPI32.dll
WS2_32.dll -C:\WINDOWS\system32\WS2_32.dll
GDI32.dll -C:\WINDOWS\system32\GDI32.dll
KERNEL32.dll -C:\WINDOWS\system32\KERNEL32.dll
The setup.py has the content like this:
from distutils.core import setup
import py2exe
setup(console=['D:\python\Feiwings.py'])
When I cd the path to dist directory, it got an error.
Traceback (most recent call last):
File "Feiwings.py", line 2, in <module>
File "PySide\__init__.pyc", line 45, in <module>
File "PySide\__init__.pyc", line 43, in _setupQtDirectories
UnboundLocalError: local variable 'path' referenced before assignment
Thanks in advance!
It seems something is wrong in your PySide distribution. From the traceback, it shows a problem in the second line of your Feiwings program. In this line there is probably an import statement where you import something from PySide, right?
Apart from the py2exe problem, are you able to execute your code normally without raising the same error?
If so, I would guess that you should include other packages dependencies (eg.: PySide) in your setup, something similar to:
setup(packages=['PySide'],
console=['D:\python\Feiwings.py'])
Hope it helps!
Check the variable 'path' in the program. It seems not a error of Pyside(assuming that you have properly installed Pyside) but the way you have used the variable 'path'. Having a look at the error it seems you have used variable 'path' before assigning it any value.
Dreamhost upgraded a number of servers this weekend, including the one I was on. It broke my configuration, so as recommended I attempted to delete the virtual environment it was running on and attempted to re-set it up. However, when I try to navigate to the site, I get this:
Traceback (most recent call last):
File "/home/thesp/mysite.com/env/lib/python2.7/site-packages/site.py", line 74, in <module>
__boot()
File "/home/thesp/mysite.com/env/lib/python2.7/site-packages/site.py", line 2, in __boot
import sys, os, os.path
File "/home/thesp/lib/python2.7/os.py", line 400, in <module>
import UserDict
File "/home/thesp/lib/python2.7/UserDict.py", line 83, in <module>
import _abcoll
File "/home/thesp/lib/python2.7/_abcoll.py", line 11, in <module>
from abc import ABCMeta, abstractmethod
File "/home/thesp/lib/python2.7/abc.py", line 8, in <module>
from _weakrefset import WeakSet
ImportError: No module named _weakrefset
I've got Python 2.7.8 installed and running, and from shell access, both in and out of my virtual environment when I run Python, I'm pulling up the correct version (which is different from the native version installed, so it's finding my setup). Other posts which reference this error message seem to think it's a problem with not having an upgraded version of virtualenv, but its version is higher than the troublesome version. (I'm running 1.11.6.)
Weirder still, I can shell into Python, type from _weakrefset import WeakSet, and I don't get import errors. I'm running Django 1.6 and I can python manage.py runserver with no errors, but the web server is throwing up before it ever sees Django.
In the traceback, the first two lines are pulling from my virtual environment, but the remaining ones don't seem to be, and I have no idea why, or even if that's relevant.
Any advice on what I should do next? I've about pulled my hair out on this one! I can post any additional information that would help troubleshoot. Thanks!
Well, I feel silly now. I went to the /home/thesp/lib/python2.7/ directory and downloaded _weakrefset.py, like so:
wget http://svn.python.org/projects/python/trunk/Lib/_weakrefset.py
...and now everything seems to be running fine. There was a _weakrefset.pyo file in the directory, so I'm not sure why _weakrefset.py never made it in, but this seems to have done the trick.
Now, that doesn't solve the mystery of why the stack trace switches directories like it does, but it's running now, so I'll take it for now!
I have some troubles understanding how python import works.
I just forked this repository and I am going to play with it but i am having troubles understanding how python import works with file in directories.
The directory structure is the following:
fitbit/
__init__.py
gather_keys_cli.py
api.py
exceptions.py
utils.py
As a preliminary step I need to run gather_keys_cli.py. It depends on api.py, which in turn depends on exceptions.py.
If I try to run it from the python interpreter everything works as expected. If I try to run it from the command line (As suggested in the documentation) I have obtain the following exception.
$./fitbit/gather_keys_cli.py KEY SECRET
Traceback (most recent call last):
File "./fitbit/gather_keys_cli.py", line 34, in <module>
from api import FitbitOauthClient
File "/Users/mariosangiorgio/FitBitHacks/python-fitbit/fitbit/api.py", line 9, in <module>
from fitbit.exceptions import (BadResponse, DeleteError, HTTPBadRequest,
ImportError: No module named fitbit.exceptions
My understanding is that when I invoke the command line the base path is set to the folder containing it. At this point, the scripts correctly imports the oauth client because it uses this instruction from api import FitbitOauthClient, which does not contain any reference to the fitbit directory.
On the opposite, api.py uses this instruction to import exceptions from fitbit.exceptions import (LIST_OF_CLASSES). This instruction contains the reference to the fitbit directory and hence I got the error.
I am not familiar with python so I'd like to understand what is the pythonic way to solve this issue.
I have the feeling that there is something clearly wrong going on and I found a workaround by moving gather_keys_cli.py and changing the api import to import fitbit.api. It works but I am not sure it is the right way to solve the issue I'm experiencing.
Hey Guys I know this has been asked before, and even various times, but I can't really figure out the exact problem with regards to my issue, even after looking at the other import errors.
It's a really basic question, so sorry for that...
I'm writing a program, we'll call it "X.py". I need to import from another file, named graphics.py so my first line of code says:
from graphics.py import *
I'm pretty sure the rest of my code is right, but when I run the program it gives me the error saying
Traceback (most recent call last):
File "/Users/me/Desktop/X.py", line 1, in <module>
from graphics import *
ImportError: No module named 'graphics'
Now I clearly have this file downloaded and I put them in a folder called Project X, together.
Any idea how I can get this program to see the other file I guess?
Thanks in advance!
Drop the .py
Instead, use:
from graphics import *
You have to download this file and put it in the same folder with your script.
From the docstring:
INSTALLATION: Put this file somewhere where Python can see it.
I installed this library called Polygon, in Python 2.7.3. But, each time I import it I get the next error message :
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "Polygon/__init__.py", line 5, in <module>
from Polygon.cPolygon import *
ImportError: No module named cPolygon
I have no idea about what could be going wrong. And also, I have already tried to contact the original author of this on his personal webpage.
but he hasn't replied though :( I wonder if someone can help me with this issue please.
It sounds like you didn't in fact install it, but instead just copied it to your working directory. As always, run setup.py with the appropriate arguments to install.
This error can happen if you try to run python from inside the directory you used to install Polygon. Move to a different directory and try again.