Whenever i execute the code below it gives me following Error:
ImportError: cannot import name 'Serial' from 'serial' (unknown location)
Code:
from serial import Serial
arduinodata = Serial('com4',9600)
print("Enter n to ON LED and f to OFF LED")
while 1:
input_data = raw_input()
print ("You Entered"+input_data)
if (input_data == 'n'):
arduinodata.write(b'1')
print("LED ON")
if (input_data == 'f'):
arduinodata.write(b'0')
print("LED OFF")
I have installed all the required python modules. Like pyserial, pyfirmata etc but it is continuously giving me this error.
I encountered the same problem. I first uninstalled pyserial from all pip, pip3, and conda (I had it on all 3), and then re-installed it. It then worked fine for me. Hope that helps!
I got exactly this problem, as well. It was caused by the "pyserial" and "serial" libraries installed on per-user basis with pip while pyserial was also installed system-wide (possibly in a different version, using the Linux package manager).
Solution
Removing the per-user version fixed the problem in my case.
Most likely missing an
__init__.py
file or the module, or the file sub-directory for the module (Serial) is on a different layer than the file executable. Hope that helps :).
I got same problem while try to install serrial on rpi4
In this tutorial
http://wiki.ros.org/rosserial_arduino/Tutorials/Arduino%20IDE%20Setup
if you install by:
2.1.1(RECOMMENDED) Installing Binaries on the ROS workstation
It work well
But if you install follow:
2.1.2 Installing from Source onto the ROS workstation
It said : ImportError: cannot import name 'Serial' from 'serial'
I dont know why, but when install by 2.1.1 it worked well.
Uninstalling serial, pyserial
pip uninstall serial
And
pip uninstall pyserial
Then reinstalling pySerial
pip install pySerial
Worked for me.
Note however that I am using a virtual environment
I had to rename serial.py to something else (serial0.py) in my C:/python39 folder and it fixed the problem.
Related
I'm trying to connect my python scripts to an MySQL or MariaDB Server on my RaspberryPi4.
My python script right now just contains import mysql.connector. But when I try to start it via sudo python3 startdb.py I just get import mysql.connector ModuleNotFoundError: No module named 'mysql' as an error.
I get an other error, when I start the script via sudo python startdb.py: import mysql.connector ImportError: No module named mysql.connector.
I searched for a solution on many sites or forums. I mostly just found various versions of pip install mysql-connector-python (also with pip3, mysql-connector-python-rf or mysql-connector) to run but none of them worked for me. The only difference I recognized is that I previously got the error ModuleNotFoundError with both sudo python and sudo python3, but now I only get it with sudo python3.
Does anyone know how to solve this?
Could the fact that my script isn't in a sub-directory of /home/pi/, but instead of /home/, be the problem?
Edit: I just tried executing the script via the desktop mode using my mouse and just clicking on run and it worked. But when I'm using the command line in desktop mode or with a SSH session it doesn't work.
Another Edit: It looks like when I'm starting the script without sudo it'll work just fine. Don't actually know why's that, but I'm good for now. But would be very interesting to know and understand why the sudo makes it "crash".
Thanks and happy to hear some solutions :D
Cooki
raspbian give user mode in running, just in Desktop gives some permission to user for run app as root to access all necessary attributes , use sudo with all initial steps when you download and install project package's
i am not able install 'copyleakscloud' library. I already installed 'copyleaks' library, but i need 'copyleakscloud' and i'm not getting any version of this library. please help!
Are you talking about this library?
You need to open a prompt (cmd on Windows or Terminal on macOS) and run
pip install copyleaks
The CopyleaksCloud is bundled with the copyleaks library. You can use it with the following code lines:
from copyleaks.copyleakscloud import CopyleaksCloud
cloud = CopyleaksCloud('ProductName', 'YOUR_EMAIL_HERE', 'YOUR_API_KEY_HERE')# You can change the product.
My resources:
Python 2.7, Ubunutu 18.04, Pycharm, virtual box oracle
I have an automation solution built in python.
The solution can be run from both cmd or pycharm of course.
2 options to run automation solution.
python main.py args a,b,c...(run 1 suite of tests)
python jenkinsRun.py arg a,b,c...(run main.py with diff args each time -lets say 5 time for instance)
Once jenkinsRun.py is runnig it will execute each main.py like this:
os.system('python main.py %s %s %s %s %s %s'%(STD,config.VpcStackName, '-dryrun', 'false', '-tenant' ,config.PROD_STAGE_Tenant))
Note that this is how I implemented it 3 years ago..could be better ways like using __import__, but need way to pass arguments, etc...
Anyway, when run:
python main.py arg a,b,c..
All good.
When run:
jenkinsRun.py
which should run main each time with diff args I get exception:
"/home/ohad/.local/lib/python2.7/site-packages/botocore/httpsession.py", line 7, in <module>
from urllib3.util.ssl_ import (
ImportError: cannot import name ssl
This happend only when I run the code on my new environment (see resources above)
last week I had old virtul box with ubuntu 15.04 (old) which everything worked well (didn't touch the vode ever since).
I have installed on new virtual box from scratch libaries, drivers, etc, etc.
Any ideas?
Could be some issue with installation. I did re-installed on MAC and it worked
sudo pip install awscli --ignore-installed six
Just to make sure: are you certain that you are invoking Python 2.x ?
Ubuntu 18.04 has Python 3.x as default, so make sure that you are not accidentally starting the script using another python version.
I had a similar error after creating a new environment (which also uses Boto3). It turned out to be a DLL error (ImportError: DLL load failed), which was caught by SSL module resulting in the error from the question: ImportError: cannot import name ssl.
Solution for me was to add an additional folder to the path: path_to_anaconda/Anaconda3/Library/bin. In that way, DLL load succeeds and the given ImportError is resolved.
I was working in PyCharm when I hit this wall.
Solved it by redirecting the path to my Anaconda environment, which I keep better provisioned and up to date.
Update the latest version of awscli resolved on my Mac by the below command line.
curl "https://awscli.amazonaws.com/AWSCLIV2-2.0.30.pkg" -o
"AWSCLIV2.pkg" sudo installer -pkg AWSCLIV2.pkg -target /
Reference:
https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-mac.html#cliv2-mac-install-cmd
After uninstalling, installing, even creating environments... this worked for me!
https://stackoverflow.com/a/60405693
In my case this issue came apparently from having colliding versions of boto3, botocore and awscli. This fixed the issue in my case:
pip install boto3 botocore awscli aiobotocore --ignore-installed
I was getting the same error on Win 10 and VS Code was pointing at the Conda interpreter. The issue was solved by installing Python 3.11 outside of Conda and pointing at the new interpreter. Don't forget to add the new Python to PATH and install boto3 afterwards.
If you are using boto3 as a dependency, there was a bug with how the boto3 dependencies were managed.
try running
pip3 install boto3 --upgrade to update boto3 and the issue should be resolved!
I am not sure why it worked. But, I had this issue in AWS Glue, and I was able to get around this problem by using Glue 3.0 instead of Glue 2.0.
Please update the latest urllib package:
run :
pip3 uninstall urllib3
pip3 install urllib3
When i used to code pynotify for python2.7 in Windows 10 then it shows an error that module object has no attribute 'init'. And i have already done to install the init module but same error occur. so what are the possible solutions for this problem?
here the code is.
import pynotify
pynotify.init("Basic")
n = pynotify.Notification("Title","Some sample content")
n.show()
It looks like the pynotify package you are looking for was initially designed for linux and was never supposed work on windows
The pynotify package installable through pip is just a name collision, and is not what not what you are looking for. (as this stackoverflow thread shows : I have already installed pynotify, still getting error no module named pynotify)
The package you want has GTK dependencies and can be installed in linux-based systems through the package management system using commands like : sudo apt-get install pynotify.
Other similar packages like notify2 (https://pypi.python.org/pypi/notify2) require linux components like dbus, and thus are not windows compatible.
If you're looking for a way to make windows 10 notifications, you can probably have look at this repository https://github.com/jithurjacob/Windows-10-Toast-Notifications.
This question already has answers here:
Importing installed package from script with the same name raises "AttributeError: module has no attribute" or an ImportError or NameError
(2 answers)
Closed 4 years ago.
I'm trying to access a serial port with Python 2.6 on my Raspberry Pi running Debian.
My script named serial.py tries to import pySerial:
import serial
ser = serial.Serial('/dev/ttyAMA0', 9600)
ser.write("hello world!")
For some reason it refuses to establish the serial connection with this error:
AttributeError: 'module' object has no attribute 'Serial'
When I try to type the same code in the interactive Python interpreter it still doesn't work.
Strangely, it used to work about a couple hours ago.
What could be the problem? I've tried to fix this for a while, installing pySerial again, rewriting my code, double-checking the serial port, etc.
I'm adding this solution for people who make the same mistake as I did.
In most cases: rename your project file 'serial.py' and delete serial.pyc if exists, then you can do simple 'import serial' without attribute error.
Problem occurs when you import 'something' when your python file name is 'something.py'.
I accidentally installed 'serial' (sudo python -m pip install serial) instead of 'pySerial' (sudo python -m pip install pyserial), which lead to the same error.
If the previously mentioned solutions did not work for you, double check if you installed the correct library.
You're importing the module, not the class. So, you must write:
from serial import Serial
You need to install serial module correctly: pip install pyserial.
You have installed the incorrect package named 'serial'.
Run pip uninstall serial for python 2.x or pip3 uninstall serial
for python 3.x
Then install pyserial if not already installed by
running pip install pyserial for python 2.x orpip3 install pyserial for python 3.x.
If you are helpless like me, try this:
List all Sub-Modules of "Serial" (or whatever package you are having trouble with) with the method described here: List all the modules that are part of a python package
In my case, the problems solved one after the other.
...looks like a bug to me...
This error can also happen if you have circular dependencies. Check your imports and make sure you do not have any cycles.
Yes this topic is a bit old but i wanted to share the solution that worked for me for those who might need it anyway
As Ali said, try to locate your program using the following from terminal :
sudo python3
import serial
print(serial.__file__) --> Copy
CTRL+D #(to get out of python)
sudo python3-->paste/__init__.py
Activating __init__.py will say to your program "ok i'm going to use Serial from python3". My problem was that my python3 program was using Serial from python 2.7
Other solution: remove other python versions
Cao
Sources :
https://raspberrypi.stackexchange.com/questions/74742/python-serial-serial-module-not-found-error/85930#85930
Tryhard