importing openbabel wrapper pybel for macos without conda - python

Previously I asked how to install openbabel for macos here. Now I also need to install the openbabel python wrapper pybel. I tried pip install pybel and it was installed. Then, while I was following the tutorial,
import openbabel
import pybel
mymol = pybel.readstring("smi", "CCCC")
I got the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'pybel' has no attribute 'readstring'
It turns out other people had similar issues and in fact I found in the mailing list that, I quote
'I guess you installed pybel via pip install pybel, which is the
"wrong" pybel'
Then they give a solution which is pip install openbabel, which is not possible for macos.
A solution is to use conda to install openbabel but I am not using conda and I would like to keep it that way so I am looking for a solution which does not require conda.

I found the solution, you can brew install open-babel and then give the path to homebrewed library of python site-packages. For me the following works:
import sys
sys.path.append('/usr/local/lib/python3.8/site-packages')
Then you can
import openbabel
from openbabel import pybel
and so on.

I have exactly the same problem. It works with the following code:
from openbabel import pybel
mymol = pybel.readstring("smi","CCN(CC)CC")
mymol

Related

no module ipaddress on python2.7.18

I'm using python 2.7.18 on Windows, and i saw that ipaddress library was exclusively for python3 so i installed py2-ipaddress using pip. When i ran pip list into cmd, it shows py2-ipaddress as installed, but when i try import ipaddress into a python file i get this
Traceback (most recent call last):
File "C:/Users/x/Downloads/main (2).py", line 1, in <module>
import ipaddress
ImportError: No module named ipaddress
Why i can't import it?
EDIT :
Actually, ipaddress works fine on python2.7.x, or it should, i installed now ipaddress using pip install ipaddress, it shows as installed when running pip show ipaddress but i still can't import it
#Matthias was right. It seems that my pip doesn't work properly, or i don't know how to use it properly. One quick fix, if you're running pycharm or any IDE with a built-in terminal is to install the module via IDE's terminal using pip install <module>.

ModuleNotFoundError: No module named 'simpleaudio'

Basically, I recently started Python. I'm working on a project where I need audio to play. I searched up some libraries that can play audio and tried simpleaudio. I'm using Windows and sucessfull installed simpleaudio using: pip3 install simpleaudio.
However, when I tried to use simpleaudio in my project with import simpleaudio as sa, it gives me this error:
Traceback (most recent call last):
File "d:\coding\python\python projects\random tests\soundtest.py", line 1, in
import simpleaudio as sa
ModuleNotFoundError: No module named 'simpleaudio'
Any idea what is wrong?
After I installed simpleaudio, import simpleaudio as sa worked with no errors. I've run into similar errors before, and it was always because the version of pip I was using and the Python interpreter I was using didn't match. You probably need to either switch to using the same interpreter as pip3 or install the package for whatever interpreter you're using
The most probable issue is the use of differing version of python. For instance if you use pip3 it is for python3 only
Since the module was not found try
pip install simpleaudio
and then importing again
It's possible you installed the library for python2 instead of python3. In ubuntu pip is python2 and pip3 is python3- I'm not sure if that's the case on windows or not.

Python: ImportError: lxml not found, please install it

I have the following code (in PyCharm (MacOS)):
import pandas as pd
fiddy_states = pd.read_html('https://simple.wikipedia.org/wiki/List_of_U.S._states')
print(fiddy_states)
And I get the following error:
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6 /Users/user_name/PycharmProjects/PandasTest/Doc3.py
Traceback (most recent call last):
File "/Users/user_name/PycharmProjects/PandasTest/Doc3.py", line 9, in <module>
fiddy_states = pd.read_html('https://simple.wikipedia.org/wiki/List_of_U.S._states')
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/io/html.py", line 906, in read_html
keep_default_na=keep_default_na)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/io/html.py", line 733, in _parse
parser = _parser_dispatch(flav)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/io/html.py", line 693, in _parser_dispatch
raise ImportError("lxml not found, please install it")
ImportError: lxml not found, please install it
In Anaconda does appear installed the last version of lxml (3.8.0). Despite of that, I have tried to reinstall it by: 1) writing pip install lxml and 2) downloading the lxml wheel corresponding to my python version (lxml-3.8.0-cp36-cp36m-win_amd64.whl), but in any case all remains the same (in the second case I get that it is not a supported wheel on this platform, even though the version of python is correct (3.6, 64 bits)).
I've read similar questions here (even with the same code above, since it's from a tutorial), but the problem still persists.
Based on the fact that the error is:
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6
This means that you are working with python-3.6. Now usually the package manager for python-3.x is pip3. So you probably should install it with:
pip3 install lxml
For people reached here using Jupyter notebook, I restarted the kernel after pip install lxml and the error is gone.
I got same error, it seems that my python3 was pointing to pandas in python2 (since I have not install pandas in python3). After doing pip3 install pandas and restarting a notebook, it worked fine.
you may have to (re)install some of your libraries pip install lxml bs4 html5lib
pd.read_html() reads with 'lxml' library by default, so try another library that you installed above like pd.read_html(some_url, flavor='html5lib')
You can go to Settings > Project Interpreter > Click on '+' icon
Find 'lxml' from the list of packages and click 'Install Package' button found below.
I am using PyCharm 2019.2.1 (Community Edition)
Build #PC-192.6262.63, built on August 22, 2019
Runtime version: 11.0.3+12-b304.39 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.15.0-58-generic
GC: ParNew, ConcurrentMarkSweep
Memory: 937M
Cores: 4
I tried to reinstall lxml without any progress.
I ended uninstalling pandas and reinstalling and updating and that solved my issues!
pip uninstall pandas
pip install pandas
pip3 install --upgrade pandas
I got the same error when trying to run some code that was using pandas. I tried some suggestions here but those did not work. Finally, what worked for me was the following two steps :
conda update anaconda
conda install spyder=5.0.5
Now when I restarted Spyder and ran my code it worked fine.
I have just installed and starting using anaconda so I don't know the root cause of this issue, but my guess is there seemed to be some "cross-connection" in the packages I had installed prior to my installation of Anaconda, and by running the above two steps now everything is running from within the Anaconda environment.
This error occurs when lxml is not installed, so just go to the terminal
and run: pip3 install lxml
I got the same problem. Trying to reinstall lxml does not work. After rereading the error message and tracing the error ~\Miniconda3\envs\mini_ds\lib\site-packages\pandas\io\html.py:872, I think I found the problem lies in the function _importers() in ~/pandas/io/html.py.
Here is the function:
def _importers() -> None:
# import things we need
# but make this done on a first use basis
global _IMPORTS
if _IMPORTS:
return
global _HAS_BS4, _HAS_LXML, _HAS_HTML5LIB
bs4 = import_optional_dependency("bs4", errors="ignore")
_HAS_BS4 = bs4 is not None
lxml = import_optional_dependency("lxml.etree", errors="ignore")
_HAS_LXML = lxml is not None
html5lib = import_optional_dependency("html5lib", errors="ignore")
_HAS_HTML5LIB = html5lib is not None
_IMPORTS = True
You can see that for lxml option, it actually tries importing "lxml.etree" instead of "lxml". So this is probably why reinstalling "lxml" would not help.
Conclusion, I think this is perhaps a problem of pandas version (mine is 1.4.1). For me, a quick solution is to specify the flavor ='html5lib' in pd.read_html().
I installed lxml 4.9.1, but it didn't work. So I tried to install lxml 4.8.0 instead, and it worked!
pip install lxml==4.8
As OP is using Anaconda, in order to solve that issue, install lxml by opening the CMD.Exe Prompt for the environment one is working on, and run
conda install -c anaconda lxml
(Source)
One can also do it by specifying the version as follows
conda install -c anaconda lxml=4.8.0
Notes:
pip doesn't manage dependencies the same way conda does and can, potentially, damage one's installation. Therefore, would recommend to use it only if conda doesn't work.
pip install lxml
# or
pip install lxml==4.9.1
If one is using pip and one has already the package installed and one is getting errors, one can pass -I (--ignore-installed) and -v as follows
pip install -Iv lxml==4.9.1
lxml official documentation can be found here.
This is their official GitHub repo.
I was seeing this issue as well on my RPi.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/pi/python3-ml/lib/python3.7/site-packages/pandas/util/_decorators.py", line 311, in wrapper
return func(*args, **kwargs)
File "/home/pi/python3-ml/lib/python3.7/site-packages/pandas/io/html.py", line 1113, in read_html
displayed_only=displayed_only,
File "/home/pi/python3-ml/lib/python3.7/site-packages/pandas/io/html.py", line 902, in _parse
parser = _parser_dispatch(flav)
File "/home/pi/python3-ml/lib/python3.7/site-packages/pandas/io/html.py", line 859, in _parser_dispatch
raise ImportError("lxml not found, please install it")
ImportError: lxml not found, please install it
Looking into /home/pi/python3-ml/lib/python3.7/site-packages/pandas/io/html.py it was attempting to use lxml.etree, so I attempted to just use that module
>>> from lxml import etree
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: libxslt.so.1: cannot open shared object file: No such file or directory
I searched for that error and found that the following packages needed to be installed on the RPi
sudo apt-get install libxslt
After installing I was successfully able to use pandas
import pandas as pd
from urllibenter code here.request import Request, urlopen
url = 'WEB-SITE'
request_site = Request(url, headers={"User-Agent": "Mozilla/5.0"})
webpage = urlopen(request_site)
dfk1 = pd.read_html(webpage, flavor='html5lib')
print(dfk1)

ImportError: matplotlib requires dateutil; import matplotlib.pyplot as plt

Am new to progamming and Python, i keep getting the error below when i run my program. Someone advised i should use pip to solve it. But cant pip get installed using the cmd. Though i suceeded using Powershell but still cant make it work. How do i solve this, any tips will go along way. Thanks
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
from satmc import satmc
File "C:\Python27\starb_models_grid1\satmc.py", line 3, in <module>
import matplotlib.pyplot as plt
File "C:\Python27\lib\site-packages\matplotlib\__init__.py", line 110, in <module>
raise ImportError("matplotlib requires dateutil")
ImportError: matplotlib requires dateutil
Am using version 2.7.3
You need to install various packages to get numpy working correctly.
libsvm-3.17.win32-py2.7
pyparsing-2.0.1.win32-py2.7
python-dateutil-2.2.win32-py2.7
pytz-2013.9.win32-py2.7
six-1.5.2.win32-py2.7
scipy-0.13.3.win32-py2.7
numpy-MKL-1.8.0.win32-py2.7
Matplotlib
Download all the binaries from this link and install and then you will have a working numpy installation.
You're probably looking for:
pip install python-dateutil
The error states that you are missing Dateutil.
This could mean that you did not install Dateutil with pip install python-dateutil or your way to install Python modules. But if you did your pip install and still get the same error it could also mean that DateUtil is installed in a folder where your Python distribution does not expect it.
In my case (Mac OSX) I installed pip with Brew http://brew.sh/. That pip will install the modules in: /usr/local/lib/python2.7/site-packages/
However the standard Mac OSX Python distribution will look for modules in /Library/Python/2.7/site-packages/
Your folders could be different of course, but you can check where Python looks for modules with:
import sys
print sys.path
Check this and see if one of the directories in the list contains the directory where dateutil is installed.
If not add a PYTHONPATH environment variable: Like: PYTHONPATH=/usr/local/lib/python2.7/site-packages/ or the folder where your dateutil is installed
I did pip install python-dateutil, but kept getting the same error. I got past that error by installing from http://www.lfd.uci.edu/~gohlke/pythonlibs/#python-dateutil
Look for the Matplotlib section and install the dependencies you don't have.
Matplotlib is a 2D plotting library.
Requires numpy, dateutil, pytz, pyparsing, six, setuptools, and optionally pillow, pycairo, tornado, wxpython, pyside, pyqt4, ghostscript, miktex, ffmpeg, mencoder, avconv, or imagemagick.

scikits.audiolab doen't import into python (numpy.dtype)

I have installed (with lots of troubles) scikits.audiolab for making sounds out of data. Now when I type:
import scikits.audiolab I get the following error
>>> import scikits.audiolab
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/scikits.audiolab-0.11.0-py2.7-macosx-10.7-intel.egg/scikits/audiolab/__init__.py", line 25, in <module>
from pysndfile import formatinfo, sndfile
File "/Library/Python/2.7/site-packages/scikits.audiolab-0.11.0-py2.7-macosx-10.7-intel.egg/scikits/audiolab/pysndfile/__init__.py", line 1, in <module>
from _sndfile import Sndfile, Format, available_file_formats, \
File "numpy.pxd", line 30, in scikits.audiolab.pysndfile._sndfile (/private/tmp/easy_install-gKE3i5/scikits.audiolab-0.11.0/scikits/audiolab/pysndfile/_sndfile.c:9632)
ValueError: numpy.dtype does not appear to be the correct type object
How do I fix this?
Any alternative package that can do the job?
I had the same issue and for me it was caused by installing another (more recent) version of NumPy.
Check if you have different versions of NumPy installed and try switching back to an older one. For my part: I had a system-wide installation of Python and common modules like NumPy, which I couldn't touch because I'm not admin on that system. So when I installed some other library locally (in ~/.local/lib/python2.7/) it would also install more recent versions of SciPy and NumPy and put them into that local folder. And when importing the module it would draw from the local directory first before looking at the system-wide libraries which were working fine before with scikits.audiolab. So for me it was solved by
pip uninstall numy && pip uninstall scipy because that only deleted the newer local versions of numpy.
But more specific to your case, here is a tutorial how (on a Mac) to switch to a certain version of NumPy:
multiple numpy version on Mac OS X
The NumPy version I found working for my scikits.audiolab is 1.6.1
>>> import numpy
>>> numpy.version.version
'1.6.1'
Hope that helps. :)
Maybe you installed/upgraded numpy after installing talkbox. Try running this command:
pip install --upgrade --force-reinstall scikits.talkbox
As suggested here:
https://github.com/ppwwyyxx/speaker-recognition/issues/13

Categories

Resources