I have a Python 2.5 project with following directory structure:
database/__init__.py
database/createDBConnection.py
gui/mainwindow.py
When I try to run
python gui/mainwindow.py
I get the error
C:\PopGen>python gui/mainwindow.py
Traceback (most recent call last):
File "gui/mainwindow.py", line 12, in <module>
from database.createDBConnection import createDBC
ImportError: No module named database.createDBConnection
In mainwindow.py, there is following statement on line 12
from database.createDBConnection import createDBC
The problem occurs because Python can't find the database module.
Question: What can I do in order to fix this error?
Here's the code of the project: https://www.dropbox.com/sh/edfutlba960atp9/MwFpaepEpl
I tried to use
C:\PopGen>python -m gui.mainwindow
but got these errors
Traceback (most recent call last):
File "C:\Python25\lib\runpy.py", line 95, in run_module
filename, loader, alter_sys)
File "C:\Python25\lib\runpy.py", line 52, in _run_module_code
mod_name, mod_fname, mod_loader)
File "C:\Python25\lib\runpy.py", line 32, in _run_code
exec code in run_globals
File "C:\PopGen\gui\mainwindow.py", line 13, in <module>
from file_menu.wizard_window_validate import Wizard
ImportError: No module named file_menu.wizard_window_validate
There are several ways to fix this, but this is perhaps the easiest one.
Try adding this in mainwindow.py, prior to the import that is failing:
import sys
sys.path.append("C:/path/to/database/module")
Related
I'm trying to configure newrelic with zope but it is returning the error:
# bin/newrelic-admin run-python bin/zeoserver fg
Traceback (most recent call last):
File "bin/zeoserver", line 22, in <module>
import plone.recipe.zeoserver.ctl
File "/opt/bitnami/apps/plone/buildout-cache/eggs/plone.recipe.zeoserver-1.2.6-py2.7.egg/plone/recipe/zeoserver/__init__.py", line 9, in <module>
import zc.recipe.egg
File "/opt/bitnami/apps/plone/buildout-cache/eggs/zc.recipe.egg-1.3.2-py2.7.egg/zc/recipe/egg/__init__.py", line 1, in <module>
from zc.recipe.egg.egg import Egg, Scripts, Eggs
File "/opt/bitnami/apps/plone/buildout-cache/eggs/zc.recipe.egg-1.3.2-py2.7.egg/zc/recipe/egg/egg.py", line 21, in <module>
import zc.buildout.easy_install
File "/opt/bitnami/apps/plone/buildout-cache/eggs/zc.buildout-2.2.5-py2.7.egg/zc/buildout/easy_install.py", line 81, in <module>
pkg_resources.Requirement.parse('zc.buildout')).location,
AttributeError: 'NoneType' object has no attribute 'location'
Does anyone know what can it be pls?
I solved adding the below code in a __init__.py from application:
import newrelic.agent
newrelic.agent.initialize('path/of/newrelic.ini')
And execute the application without the command "newrelic-admin run-python".
Newrelic worked but with limitations because don't have official support yet.
I'm attempting to use Xlwings for Python, however having installed Python 3.5, pywin32 extensions and Xlwings I get the following error when starting import:
from xlwings import workbook
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
from xlwings import workbook
File "C:\Python 3.5\lib\site-packages\xlwings\__init__.py", line 18, in <module>
from . import _xlwindows as xlplatform
File "C:\Python 3.5\lib\site-packages\xlwings\_xlwindows.py", line 15, in <module>
import pywintypes
File "C:\Python 3.5\lib\site-packages\win32\lib\pywintypes.py", line 124, in <module>
__import_pywin32_system_module__("pywintypes", globals())
File "C:\Python 3.5\lib\site-packages\win32\lib\pywintypes.py", line 117, in __import_pywin32_system_module__
assert sys.modules[modname] is not old_mod
AssertionError
Try commenting out the asserts (replace them with a pass) and see if it works. Otherwise you're going to need to debug pywintypes.
Felix Zumstein just informed me that the above suggestion won't work:
When you comment out those lines, then it fails further down when doing from pywintypes import TimeType: ImportError: cannot import name 'TimeType'
However, downgrading may solve this problem.
After Much trial and error ive found that downgrading to Python 3.3 works
Thnak you for all the responses
I have successfully installed cherrypy but when I try to import it, I get following error. I am a newbie and have spent quite a bit of time trying to get this to work, so any help would be highly appreciated.
Traceback (most recent call last):
File "unitconverter.py", line 1, in <module>
import cherrypy
File "c:\Python34\lib\site-packages\cherrypy-3.2.0-py3.4.egg\cherrypy\__init__
.py", line 82, in <module>
from cherrypy import process
File "c:\Python34\lib\site-packages\cherrypy-3.2.0-py3.4.egg\cherrypy\process\
__init__.py", line 14, in <module>
from cherrypy.process import plugins, servers
File "c:\Python34\lib\site-packages\cherrypy-3.2.0-py3.4.egg\cherrypy\process\
plugins.py", line 424, in <module>
class PerpetualTimer(threading._Timer):
AttributeError: 'module' object has no attribute '_Timer'
From what I can see, it's a bug with that version of CherryPy. You'd be best upgrading to a more recent version instead.
Traceback (most recent call last):
File "D:\Program Files\JetBrains\PyCharm 3.0.1\helpers\pydev\pydevd.py", line 2, in <module>
from django_debug import DjangoLineBreakpoint
File "D:\Program Files\JetBrains\PyCharm 3.0.1\helpers\pydev\django_debug.py", line 3, in <module>
from pydevd_comm import CMD_SET_BREAK
File "D:\Program Files\JetBrains\PyCharm 3.0.1\helpers\pydev\pydevd_comm.py", line 107, in <module>
import pydevconsole
File "D:\Program Files\JetBrains\PyCharm 3.0.1\helpers\pydev\pydevconsole.py", line 6, in <module>
from code import compile_command
ImportError: cannot import name compile_command
My Code is the simple webpy example,there is no problem with it。
Most likely you've created a module named code.py.
If you do this, it hides the stdlib module code, so anything that needs to use that module will find your module instead.
And the reason you get this error is that your code module doesn't have anything named compile_command.
In general, you always want to avoid giving your modules the same name as anything in the stdlib, or any site-packages you've installed. You can work around this by, e.g., organizing your modules into packages instead of leaving them all at the top level, but it's easier to just not re-use the names.
I love ipython, I am learning python now as a replacement of R for data analysis. However at promt I get the following message:
$ ipython --qtconsole
Traceback (most recent call last):
File "/Library/Frameworks/EPD64.framework/Versions/Current/bin/ipython", line 5, in <module>
from IPython.frontend.terminal.ipapp import launch_new_instance
File "/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/IPython/__init__.py", line 46, in <module>
from .frontend.terminal.embed import embed
File "/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/IPython/frontend/terminal/embed.py", line 39, in <module>
from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell
File "/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/IPython/frontend/terminal/interactiveshell.py", line 33, in <module>
from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC
File "/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 44, in <module>
from IPython.core import prefilter
File "/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/IPython/core/prefilter.py", line 48, in <module>
from IPython.utils.traitlets import (
ImportError: cannot import name CRegExp
Ipython worked just fine a week ago and now I get this error. Can anybody suggest what might be causing this?
As #favoretti mentioned, this is an import issue in utils.traitlets.
I would recommend upgrading to EPD 7.3 and see if that fixes the issue. I feel bad suggesting a "brush it under the carpet" solution but if you're just starting out with python delving into the bowels of IPython might be a bit of a headache.