I need to import serial library in my python project that uses PyQt to build user inteface.
To list all avcailable serial ports I tried to use this command:
import serial
...
def findComPorts(self):
list=serial.tools.list_ports_osx.comports()
port=serial.Serial('...',baudrate=38400)`
but eclipse shows the error: Undefined variable from import: tools
I also tried:
from serial import tools
...
def findComPorts(self):
list=tools.list_ports_osx.comports()
port=serial.Serial('...',baudrate=38400)
but now the error at runtime is: AttributeError: 'module' object has no attribute 'list_ports_osx'
I'm running Eclypse Kepler, Python 2.7, pySerial 2.7 installed via macports
Related
I have a Windows 10 with Python 3.7.4 and I use Jupyter Notebook. I'm trying to use pySerial to connect to my Arduino by Serial attribute. I tried installing pySerial simply by pip install pyserial and eventually I tried conda install -c conda-forge pyserial too, but when I try to run my code:
import serial
ser = serial.Serial('COM4', 9600)
I get an error message like:
AttributeError Traceback (most recent call last)
<ipython-input-7-413d0d9dabe7> in <module>
2 import serial
3 import time
----> 4 ser = serial.Serial('COM4', 9600)
5
6 # Your Account Sid and Auth Token from twilio.com/console
AttributeError: module 'serial' has no attribute 'Serial'
Also, I tried
import serial
serial.__file__
And I got 'C:\Users\lippe\Anaconda3\lib\site-packages\serial\__init__.py' as output.
I also tried dir(serial) and I can't see the Serial attribute in the output, so I think it's basically not installed and I don't know why.
I tried digging the internet but I still can't find a solution.
Make sure you're importing the right serial. After installing pyserial with pip, you can use the __file__ attribute to check that it's the one I expect like so:
>>> import serial
>>> serial.__file__
'/usr/local/lib/python3.7/site-packages/serial/__init__.py'
Other answers suggest it might work to import the class directly with
from serial import Serial
But I'm not sure why this would matter if you're importing the latest published on pypi.
I am new to ROS and python. This question could be silly but spent almost 5 hours on this. I am using PyCharm (Latest version) with Python 2.7.15 64 bit (Also tried with 3.x). I need to import a few libraries as below:
import roslib;
roslib.load_manifest('smach_tutorials')
import rospy
import smach
import smach_ros
However, PyCharm fails to identify roslib, rospy, smach and smach_ros (could not find in the interpreter also to import). The above libraries are example given in the official site:
http://wiki.ros.org/smach/Tutorials/Simple%20State%20Machine
OS: Windows 7 (64 bit)
ROS not installed: ("SMACH is a ROS-independent Python library to build hierarchical state machines" - from the official site)
Error Traceback:
Traceback (most recent call last):
File "C:/Users/****/Desktop/Python/TestCharm.py", line 3, in <module>
import roslib;
ModuleNotFoundError: No module named 'roslib'
If you are using the catkin version of ROS (Groovy and later), it does not use the manifest file but uses the package.xml file instead.
So your code will be:
import rospy
import smach
Apparently, your code is ready for ROS Fuerte or earlier version.
With supposing that Smach is ROS-independent, you need only to the import smach
Thanks for all the support. I found out it is not possible for my perticular case to use SMACH because it has dependency on catkin. I am using Windows 7 and should be upgraded to windows 10 or use Ununtu Linux.
I am trying to connect to the shopify api but am having difficulty connecting when using Eclipse+PyDev. When connection via python in a bash shell the same commands work OK
to install:
pip3 install --upgrade ShopifyAPI
shopify.py (my code)
import shopify
shop_url = "https://APIKEY:PASSWORD#mystore.myshopify.com/admin/products.json
shopify.ShopifyResource.set_site(shop_url)
The reference to shopify.ShopifyResouce.. throws the following in PyDev:
AttributeError: 'module' object has no attribute 'ShopifyResource'
I think it may be due to relative imports in the shopify module (the same code works fine in a terminal).
In shopify.py: (shopify API)
from shopify.resources import *
in shopify.resources: (shopify API)
from ..base import ShopifyResource
When I run
from shopify.base import ShopifyResource
ShopifyResource.set_site(shop_url)
I get ImportError: No module named 'shopify.base'; 'shopify' is not a package
Any ides how I can fix this?
The problem might be you created a shopify.py file in your IDE rename that file and that error will be solved
I want to create a web server using http.server module in Python. But when execute the code it shows an error ImportError: cannot import name 'BaseHTTPRequestHandler'
I have Python27 and Python34 both installed on the same system.
I have installed Scapy from the package repos on my Ubuntu machine (Python 2.7), and I am trying to run this code from a file:
import scapy
dg = scapy.IP()
pcap = scapy.rdpcap("../tst/Http.cap")
scapy.send(IP())
Running gives the error,
AttributeError: 'module' object has no attribute 'IP'
Comment out the IP call on line 3 and running gives the error,
AttributeError: 'module' object has no attribute 'rdpcap'
Also comment out line 4 and you get,
AttributeError: 'module' object has no attribute 'send'
Curously, this code fails when invoked with ''python '', but it works as expected when I manually enter each command into the Python shell. I have observed this behaviour on three fresh Python installs - two in Ubuntu, and one in Windows. Can anyone else see the cause of this error?
You need to import Scapy into the global namespace.
From the Scapy module documentation -
Note: In Scapy v2 use from scapy.all import * instead of from scapy import *.
Also found in "Using Scapy to build your own tools".
So your code should be -
from scapy.all import *
dg = IP()
pcap = rdpcap("../tst/Http.cap")
send(IP())