ImportError: No module named serial in Linux - importerror

I encountered a problem with topic is ImportError: No module named serial by I use it in Linux ubuntu 20.04, and my python version is 3.8.10.
Traceback (most recent call last):
File "/home/prawee/catkin_ws/src/ros_myo_2/scripts/myo-rawNode.py", line 9, in <module>
import serial
ImportError: No module named serial
And I have pyserial version 3.5 installed. I have tried repeating the serial install which says this.
Requirement already satisfied: pyserial in /usr/local/lib/python3.8/dist-packages (3.5)
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
WARNING: There was an error checking the latest version of pip.
I wonder if this warning is related to problem?
This problem just happened for the first time. Before this I was able to use it normally. I have tried many ways but still don't understand how to fix it, please help me.
I am stuck in a problem import serial which I hope to be able to fix and use it again the way it used to be.

Related

PyGreSQL - Unable to Insert Data

I am using CentOS-6 with Python 3.8, PostgreSQL 12 and PyGreSQL 5.2.2. This is the error I get trying to insert data into my database.
>>> db.insert('settings', None, **data)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.8/site-packages/pg.py", line 2322, in insert
adapt = params.add
File "/usr/local/lib/python3.8/site-packages/pg.py", line 1667, in __getattr__
if self.db:
AttributeError: 'pg.Connection' object has no attribute 'escape_identifier'
Can anyone point me towards what is wrong?
The method escape_identifier on the connection corresponds to the function PQescapeIdentifier in libpq. It exists since PostgreSQL 9 which is required by PyGreSQL 5.2. PyGreSQL does not compile support for these functions if it is installed with the no-escaping-funcs option or if it thinks PostgreSQL is older than version 9.
Since you say that you have PostgreSQL 12 installed, a possible explanation could be that you still have the client library (libpq) of an old PostgreSQL version installed as well, and the pg_config tool reports that old version. You should check this with pg_config --version. The pg_config tool is in libpq-devel, so make sure you have libpq and libpq-devel installed for PostgreSQL 12.
You can also try to explicitly enable the escaping functions by installing PyGreSQL with python setup.py build_ext --escaping-funcs install, but you will still need the latest libpq, and there will be other functions disabled as well when PyGreSQL thinks that libpq is too old. So the proper solution is to make sure libpq is up to date and pg_config --version reports the corresponding PostgreSQL version.

PyAudio import error : ImportError: DLL load failed: The specified module could not be found

I encountered an import problem by PyAudio.
I have a winodws 10, 64 bit, and use Anaconda and Spyder IDE with python 3.7.
I installed PyAudio in Ananconda, ran as administrator, with these commands :
cd
conda install -c conda-forge PyAudio
The installation ran without any problems.
I then restarted both Anaconda and SPYDER. PyAudio now shows up in Anaconda's list of installed packages.
When I try to import Pyaudio in Spyder (IPython console), I encounter this error message :
[1]: import pyaudio
Could not import the PyAudio C module '_portaudio'.
Traceback (most recent call last):
File "", line 1, in
import pyaudio
File "C:\ProgramData\Anaconda3\lib\site-packages\pyaudio.py", line 116, in
import _portaudio as pa
ImportError: DLL load failed: The specified module could not be found.
I tried to fix it by answers to similar ImportError message issued, while other users tried to import other packages like SKlearn ... , but with no success.
Your problem (and mine) are the same. The issue is, unfortunately, the version of python you're running (in tandem with your OS).
Check out this link:
https://people.csail.mit.edu/hubert/pyaudio/#:~:text=Note%3A%20As%20of%20this%20update,4.
Under the INSTALLATION section in the link for WINDOWS, PyAudio's latest version (0.2.11) is compatible with Python versions: 2.7, 3.4, 3.5, 3.6.
My current python is 3.8.5, so you (and I) could never use PyAudio unless they added compatibilities or we revert to an above python version.
I tried to install portaudio using
conda install portaudio
but it seems like it didn't work as it should be. However,
conda install -c anaconda portaudio
solved the problem.
see the official anaconda page

DLL load failed : Python modules accessible through Spyder but import fail in cmd

I have seen many more or less related questions on this topic, but none helped me finding a way to solve my problem.
I'm not very familiar with Windows environment, deep apologies if my question sounds obvious to some extent.
Setup:
Windows 10
Python 3.7.0 (installed through latest Anaconda release)
Spyder 3.3.1
Im running a Python, that involves several modules import. I came across some module issues. For example:
from PIL import Image as PIL_Image
Works smooth in Spyder, but gives (error message in french but I guess you got the point):
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\my_user_name\Anaconda3\lib\site-packages\PIL\Image.py", line 64, in <module>
from . import _imaging as core
ImportError: DLL load failed: Le module spécifié est introuvable.
If executed in Powershell or cmd.
What I tried:
Appending Anaconda's install path to my path variable before I open Powershell:
$Env:path += ";C:\Users\my_user_name\Anaconda3;C:\Users\my_user_name\Anaconda3\Scripts"
Checking that sys.path is the same in Powershell and Spyder. For both, it looks like:
['',
'C:\\Users\\my_user_name',
'C:\\Users\\my_user_name\\Anaconda3\\python37.zip',
'C:\\Users\\my_user_name\\Anaconda3\\DLLs',
'C:\\Users\\my_user_name\\Anaconda3\\lib',
'C:\\Users\\my_user_name\\Anaconda3',
'C:\\Users\\my_user_name\\AppData\\Roaming\\Python\\Python37\\site-packages',
'C:\\Users\\my_user_name\\Anaconda3\\lib\\site-packages',
'C:\\Users\\my_user_name\\Anaconda3\\lib\\site-packages\\win32',
'C:\\Users\\my_user_name\\Anaconda3\\lib\\site-packages\\win32\\lib',
'C:\\Users\\my_user_name\\Anaconda3\\lib\\site-packages\\Pythonwin',
'C:\\Users\\my_user_name\\Anaconda3\\lib\\site-packages\\IPython\\extensions',
'C:\\Users\\my_user_name\\.ipython']
What else could explain that my import fails outside of Spyder ?
Ok I could not find a clean way out, so let me just share my experience in case someone finds it helpful ...
The DLL failure with PIL related libs seems to be a known issue. See further explanations:
https://github.com/python-pillow/Pillow/issues/2945
PIL: DLL load failed: specified procedure could not be found
How I solved my issue:
Cleanly uninstalled anything related to Python on my laptop. Both Anaconda, isolated Python installs, Spyder ...
Re-installed the latest Anaconda. It happens to come with Python 3.7.1 instead of 3.7.0
Re-did my PIP installs of everything. Note I had to append Anaconda\Library\bin to my Windows path for PIP to work completely, which I don't recall having done with my previous installation.

Issue with dependencies running python file on another PC

I have a python file running perfectly in the IDE.
I want to run it on a different PC without any IDE.
I run the program from the command line: python program.py
Error message: File "program.py", line 8, in
from mpl_finance import candlestick_ohlc
ModuleNotFoundError: No module named 'mpl_finance'
When trying: pip install mpl_finance (or pip install mpl_toolkits)
I get the message: No matching distribution found for mpl_finance (or mpl_toolkits)
There also seems to be a problem with matplotlib backend.
Looking for a solution please.
After many failed paths, here's what worked:
matplotlib.finance is deprecated and it is now mpl_finance.
Create 2 files named mpl_finance.py and setup.py and get their contents from here.
Then from the command-line: python setup.py install
Fixing the backend (this can save you a few days):
If the backend of matplotlib was set in a file original PC (and not in the code). Then you need to do the same on the second PC.
Windows Path: C:\Program Files\Python36\Lib\site-packages\matplotlib\mpl-data\matplotlibrc
Change (probably line 38) to this: backend : Qt5Agg

Distutils.core could not be found, where can I download it

Traceback (most recent call last):
File "setup.py", line 26, in <module>
from distutils.core import setup, Extension, Command
ImportError: No module named distutils.core
I get this error when installing ctypes.py on openwrt. Unfortunately, I cannot find the download link to the setup for distutils.core.
Can someone point me to it?
distutils ships in Python’s standard libary. Some operating systems think it’s not a regular module but only interesting for developers, so they move it to a python-devel package together with C headers, config files and co. https://dev.openwrt.org/ticket/793 tells me that this is the case for OpenWRT: you need to install python-dev to get distutils installed.
While logged in to openwrt try:
opkg update
opkg install distribute