Showing ImportError: cannot import name 'Message' from 'can' - python

I am importing CAN messages in Python and I am using python-can library. So the line in my python code here is:
from can import Message
It was working fine but after I changed the folders, I am getting the below error:
Traceback (most recent call last):
File "/home/rafi/PycharmProjects/Right Turn/CAN_simulator_Recv.py", line 12, in <module>
from can import Message
ImportError: cannot import name 'Message' from 'can' (/home/rafi/.local/lib/python3.8/site-packages/can/__init__.py)
Can anyone help me with this error? Maybe it has something to do with directory or packages? The same can library is working fine in other linux machines. I tried uninstalling python-can but it doesn't work.
Please help.

It's some kind of import bug. Try import Message like this:
from can.message import Message
Everything worked for me.

Related

Error on calling a function from another file on python

I'm getting an error on importing a function from another file in python.
This is my file structure
In checkSpellings.py there's a function defined as spellchecker(tokenized_text) . And I'm trying to use it by importing it on main.py by following code
from checkSpellings import spellChecker
But it gives me an warning (red underline on top of both of checkSpellings(file name) and spellChecker(function name) in import code). This previously happened and I though this is purely an issue with intellisense . Because last time same thing happened (gave me the warning), but the code worked fine.
But now when I run the main.py it gives me an error saying
Traceback (most recent call last):
File "/home/pankaja/Documents/PycharmProjects/BookDigitizer/OCR_Correction/main.py", line 1, in <module>
from checkSpellings import spellChecker
ImportError: cannot import name 'spellChecker
How can I fix this ? What have I done wrong ?
IMPORTANT : Here I'm using python3.6 interpreter on an anaconda virtual environment. Might it be an issue ?
The function is spellchecker but you tried to import spellChecker.

Python 'cannot import name 'TestCase'' When importing unittest

Whenever I attempt:
import unittest
I get the following error:
Traceback (most recent call last):
File "wackyTesting.py", line 1, in <module>
import unittest
File "C:\.....\Python\Python36\lib\unittest\__init__.py", line 59, in <module>
from .case import (TestCase, FunctionTestCase, SkipTest, skip, skipIf,
ImportError: cannot import name 'TestCase'
This happens regardless of where the code is run, there is nothing in the root that could be causing a conflict. I have tried re-installing unittest but it didn't help. It was working perfectly until just recently. Any ideas?
Welp, I just uninstalled python completely and reinstalled. Nothing quite like turning it off and on again. That seems to have done it, maybe there's a more elegant solution but this will have to do for now.

Errors importing pyodbc

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.

python email script doesn't work on mac os x 10.9

I started trying to make a script to send emails using python, but nothing worked. I eventually got to the point where I just started copying and pasting email scripts and filling in my info. Still nothing worked. So i eventually just got rid of everything except this:
#!/usr/bin/python
import smtplib
This still did not work. Can someone explain to me why this doesn't work? I'm sure its really simple. I'm using mac os x 10.9 if that makes a difference. here is my error:
Traceback (most recent call last):
File "the_email.py", line 2, in <module>
import smtplib
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 46, in <module>
import email.utils
ImportError: No module named utils
Change the name of your script from email.py to something else. It is interfering with the Python standard library module of the same name, email.
Read this: Syntax: python smtplib not working in script
A user says that you have to remove email.py from the folder.

Import error in Python: Polygon

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.

Categories