I'm having trouble with a simple twisted program and when run I get the following error:
Traceback (most recent call last):
File "serial.py", line 1, in <module>
from twisted.internet.serialport import SerialPort
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/twisted/internet/serialport.py", line 22, in <module>
import serial
File "/Users/me/Desktop/serial.py", line 1, in <module>
from twisted.internet.serialport import SerialPort
ImportError: cannot import name SerialPort
I did have a bunch of fancy code, but I determined that the following line is the problem:
from twisted.internet.serialport import SerialPort
I'm running Twisted 13.2.0, Python 2.7 both updated as well as PySerial 2.7 installed. So I believe everything is installed and up to date. This error occurs on two different systems.
The following runs without issue:
python -c "from twisted.internet.serialport import SerialPort"
Thanks for your help. Is it some conflict with PySerial?
Look at these lines of the traceback:
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/twisted/internet/serialport.py", line 22, in <module>
import serial
File "/Users/me/Desktop/serial.py", line 1, in <module>
from twisted.internet.serialport import SerialPort
Here you see that .../twisted/internet/serialport.py is doing this:
import serial
This is a line from Twisted. You can guess based on this fact that the serial module the code wants to import is not something that you have written.
Then look at the next file in the traceback: /Users/me/Desktop/serial.py. This tells you that Python found the serial module in your personal desktop directory. import serial is now running code you wrote. Based on the previous surmise, this is likely a bad thing.
Get rid of serial.py (and serial.pyc and serial.pyo if they exist) and try again. It still may not work but the cause of the problem (and therefore the traceback) should at least be different.
Related
I have a strange problem after I moved an application to a different folder. I copied all files inside the old folder to the new directory and then tried to restart the application. However when I do so I get the error message:
Traceback (most recent call last):
File "bin/zeoserver", line 24, in <module>
import plone.recipe.zeoserver.ctl
File "/usr/local/Plone/buildout-cache/eggs/plone.recipe.zeoserver-1.3.1-py2.7.egg/plone/recipe/zeoserver/__init__.py", line 1, in <module>
import logging
File "/usr/local/Plone/Python-2.7/lib/python2.7/logging/__init__.py", line 26, in <module>
import sys, os, time, cStringIO, traceback, warnings, weakref, collections
ImportError: No module named time
This is particularly intriguing as time should be a pre-installed Python package. What is also interesting is that after renaming the old folder to xyz_old I cannot start the application from there either.
What could cause such an issue?
My background is Java/C++ and I'm very new to python. I'm trying to import pyodbc to my project which works alright if I do it via command line.
import odbc
However, when I try to do the same in pydev/eclipse, i get the following error which I cannot find a solution to. I suspect this may have something to do with Eclipse setup
Traceback (most recent call last):
File "C:\Users\a\workspace\TestPyProject\src\helloworld.py", line 2, in <module>
import pyodbc
File "C:\Users\a\AppData\Local\Continuum\Anaconda3\Lib\site-packages\sqlalchemy\dialects\mssql\pyodbc.py", line 105, in <module>
from .base import MSExecutionContext, MSDialect, VARBINARY
ImportError: attempted relative import with no known parent package
I'm really stuck here and any hints will be appreciated!
An incorrect library was imported into the External Libraries list of the project. After fixing it, the import is working.
I've recently installed python, ipython and pip, with pip I've installed the socket library, and plenty others, now I can't import socket while running python program through cmd but I can do it using ipython,
When I run ipython and I import socket everything works fine,
now I wrote a simple script, called "tcp.py" and all it contains is nothing but the following line
Import Socket
Traceback (most recent call last):
File "C:\dir\desktop\tcp.py", line 1, in <module>
import socket
File "C:\dir\desktop\socket.py", line 1, in <module>
socket
NameError: name 'socket' is not defined
Any idea how to solve this?
You've made two mistakes: the first is to have your own file named "socket.py". This shadows the stdlib module, so when you import socket, it finds your file instead of the module in the stdlib. The second mistake is that your "socket.py" file has the word socket in it. This is what is actually causing your error: the word socket is undefined.
Delete your "socket.py" file, and any *.pyc files lying around, and the problem will be fixed.
If you read the traceback (error report) closely, you can see what's happened.
Im trying to figured out this problem. Yesterday I installed PyScripter and since then, scripts doesnt work. When I run any script (in PyScripter or IDLE) and trying to "import arcpy", it gets this error:
import arcpy
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import arcpy
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\__init__.py", line 17, in <module>
from geoprocessing import gp
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\__init__.py", line 14, in <module>
from _base import *
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 14, in <module>
import arcgisscripting
File "C:\Python26\ArcGIS10.0\lib\arcgisscripting.py", line 81, in <module>
from RuntimeError import RuntimeError
ImportError: No module named RuntimeError
Have somebody any suggestion how to fix it?
Thanks to all very much!
Sounds like the module is not installed properly (or at all). To verify, do the following:
open a shell and start the python shell by typing python
(If this doesn't display an error, check that python is added to your system path or if it is even installed at all. But if you've used Python on said machine maybe system path issue)
enter the commmand help('modules')
review the list of modules that's returned to see whether arcpy is included
if not, then you may have to reinstall the module
I am following the tutorial(http://pyusb.sourceforge.net/docs/1.0/tutorial.html)
I am on windows xp sp3,
my python version is 2.7 and I downloaded and installed the pyusb-1.0.0-a1.zip
and libusb-win32-bin-1.2.4.0.zip
import usb
works fine
but
import usb.core
doesn't working at all
it says
Traceback (most recent call last):
File "D:\py\usb.py", line 1, in <module>
from usb import core
File "D:\py\usb.py", line 1, in <module>
from usb import core
ImportError: cannot import name core
any solution?
thanks!
p.s.
"from usb import core"
this make
Traceback (most recent call last):
File "D:\py\usb.py", line 1, in <module>
from usb import core
File "D:\py\usb.py", line 1, in <module>
from usb import core
ImportError: cannot import name core
full source code is here
from usb import core
#find device
dev = usb.core.find(idVendor=0x1516, idProduct=0x8628)
#found?
if dev is None :
raise ValueError('device not found')
#set the active config. with no args, the first config will be the active one
dev.set_configuration()
#get an end point instance
ep = usb.util.find_descriptor(
dev.get_interface_altsetting(), #first interface
#match the first Out Endpoint
custom_match = \
lambda e: \
usb.util.endpoint_direction(e.bEndpointAddress) == \
usb.util.ENDPOINT_OUT)
assert ep is not None
while(1):
ep.write(0x5553424350DDBC880000000000000600000000000000000000000000000000)
ep.write(0x5553425350ddbc880000000000)
Your question says you're using 1.0, but I had the same symptoms as you did, so I'll put this here for future search-engine users.
If you can import usb but not import usb.core you may be running python-usb 0.x instead of 1.0.
https://github.com/walac/pyusb
In both cases error is:
Traceback (most recent call last):
File "D:\py\usb.py", line 1, in <module>
which means it has file usb.py in PATH earlier (probably in . which is D:\py\ in this case) than path to python modules.
Did you install this module properly? Try rename this usb.py file to something else, you'll see if the error becomes "ImportError: No module named usb". Also check Python install path (something like C:\Python27\) for usb folder i.e. <python_path>\lib\site-packages\usb\core.py.
I suppose that "D:\py\usb.py" is the name of your py test program.
Unfortunately this make confusion to the py compiler due to the fact that usb is also the name of the module.
Change it in usbtest.py and everything works
for understanding where python looks to import your module, you can run following code :
import sys
print(sys.path)
this will show you list of directory names that python searches for your module to import :)