ImportError: No module named yaml in /usr/lib/ but present in /usr/lib64 - python-2.7

I have gone through the answers from SO but didn't find the one which i am looking for
I am getting below error
import ansible.constants as C
File "/usr/lib/python2.7/site-packages/ansible/constants.py", line 15, in <module>
from ansible.config.manager import ConfigManager, ensure_type, get_ini_config_value
File "/usr/lib/python2.7/site-packages/ansible/config/manager.py", line 17, in <module>
from yaml import load as yaml_load
ImportError: No module named yaml
although yaml is present in
/usr/lib64/python2.7/site-packages
What should be done to resolve this issue or to install PyYAML properly in RHEL7

Related

Can't find sklearn module

from sklearn import datasets
digits = datasets.load_digits()
print(digits)
This is the error I get when using sklearn. However, I have the module installed and updated. Is there an easy way to reinstall the module via terminal? Is there another mistake I didn't notice (ex: importing the wrong module)?
Traceback (most recent call last):
File "/Users/patrickmaynard/scikitLearn/driver/driver.py", line 11, in <module>
from sklearn import datasets
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sklearn/__init__.py", line 57, in <module>
from .base import clone
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sklearn/base.py", line 10, in <module>
from scipy import sparse
ImportError: No module named scipy
Credit goes to Evert
Even if the sklearn module is fully installed, it will not work unless the scipy module is also installed.

Problems with CPLEX Python API on a mac

I have read many posts about problems but none of them can solve mine. Although I have been following this blog exactly I still get this error when I try to run one of the example src python files:
Traceback (most recent call last):
File "facility.py", line 25, in <module>
import cplex
File "/Users/sb/Applications/IBM/ILOG/CPLEX_Studio1251/cplex/python/x86_darwin/cplex/__init__.py", line 43, in <module>
import callbacks
File "/Users/sb/Applications/IBM/ILOG/CPLEX_Studio1251/cplex/python/x86_darwin/cplex/callbacks.py", line 48, in <module>
from _internal._aux_functions import apply_freeform_two_args, apply_freeform_one_arg
File "/Users/sb/Applications/IBM/ILOG/CPLEX_Studio1251/cplex/python/x86_darwin/cplex/_internal/__init__.py", line 22, in <module>
import _list_array_utils
File "/Users/sb/Applications/IBM/ILOG/CPLEX_Studio1251/cplex/python/x86_darwin/cplex/_internal/_list_array_utils.py", line 13, in <module>
import _pycplex as CPX
File "/Users/sb/Applications/IBM/ILOG/CPLEX_Studio1251/cplex/python/x86_darwin/cplex/_internal/_pycplex.py", line 19, in <module>
_pycplex_platform = swig_import_helper()
File "/Users/sb/Applications/IBM/ILOG/CPLEX_Studio1251/cplex/python/x86_darwin/cplex/_internal/_pycplex.py", line 15, in swig_import_helper
_mod = imp.load_module('_pycplex_platform', fp, pathname, description)
File "/Users/sb/Applications/IBM/ILOG/CPLEX_Studio1251/cplex/python/x86_darwin/cplex/_internal/_pycplex_platform.py", line 23, in <module>
from cplex._internal.py1013_cplex1251 import *
ImportError: dlopen(/Users/sb/Applications/IBM/ILOG/CPLEX_Studio1251/cplex/python/x86_darwin/cplex/_internal/py1013_cplex1251.so, 2): no suitable image found. Did find:
/Users/sb/Applications/IBM/ILOG/CPLEX_Studio1251/cplex/python/x86_darwin/cplex/_internal/py1013_cplex1251.so: mach-o, but wrong architecture
Unfortunately I am not familiar with the /.bash_profile but what is posted in the link I added at the end.
Can please someone help me out here?
A possible solution to this would be to check whether you can copy the cplex directory manually over towards the site-packages that are installed (you may need to use sudo).
From your stacktrace I see that you have installed cplex into
/Users/sb/Applications/IBM/ILOG/CPLEX_Studio1251/cplex/python/x86_darwin/
First run (I assume you python 2.7) in the interactive shell:
import site; site.getsitepackages()
See How do I find the location of my Python site-packages directory? for details about this step.
This will give you the directory of the site-packages where you need to copy the "cplex" directory to. I assume it is /Library/Python/2.7/site-packages from here
on a mac then run:
sudo cp -r ./cplex /Library/Python/2.7/site-packages/
This sets up the cplex manually as an importable package for your python installation. You should therefore be able to import cplex within the python interactive shell.

Pyinstaller with PIL. ImportError: cannot import name _imaging

I am having trouble running a compiled executable that includes pillow. I have used pyinstaller which seems to compile well enough, however after running the exe, an error is thrown. Seems there is a conflict with '_imaging' being referenced instead of 'Image'.
First off, I find it strange how pillow installs to a PIL directory rather than a pillow and the modules are also referenced as PIL. I doubt that has anything to do with the problem though.
There isn't actually a _imaging.py file in Python27\Lib\site-packages\PIL however and I suspect this might be a problem as somehow pyinstaller has made the executable require it. Not sure if there is some way to exclude it from the build. This may be a next step.
Issues like this and thishave been raised but not solved. Some also refer to PIL not being uninstalled before installing pillow, but PIL is definitely uninstalled and I have tried both binaries and pip installs of pillow.
Any suggestions?
Error from runtime:
Traceback (most recent call last):
File "<string>", line 26, in <module>
File "C:\Python27\Lib\site-packages\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "C:\Users\Hp\PycharmProjects\GISdev\build\gis_helper2\out00-PYZ.pyz\PIL.PngImagePlugin", line 40, in <module>
File "C:\Python27\Lib\site-packages\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "C:\Users\Hp\PycharmProjects\GISdev\build\gis_helper2\out00-PYZ.pyz\PIL.Image", line 63, in <module>
ImportError: cannot import name _imaging
Extract from the PIL.Image file is below and the offending line is
from PIL import _imaging as core
try:
# If the _imaging C module is not present, Pillow will not load.
# Note that other modules should not refer to _imaging directly;
# import Image and use the Image.core variable instead.
# Also note that Image.core is not a publicly documented interface,
# and should be considered private and subject to change.
from PIL import _imaging as core
if PILLOW_VERSION != getattr(core, 'PILLOW_VERSION', None):
raise ImportError("The _imaging extension was built for another "
" version of Pillow or PIL")
from PIL import Image
And this is how I am calling pillow from my script:
from PIL import Image

ImportError when importing scipy.stats, undefined symbol (scipy version 0.14.0)

I just upgraded to Scipy 0.14.0 and Ubuntu 14.04. Now when I try to import stats I get an ImportError.
import scipy.stats as stats
Traceback (most recent call last):
File "/home/user1/Documents/test/importTest/importScipy.py", line 1, in <module>
import scipy.stats as stats
File "/usr/local/lib/python2.7/dist-packages/scipy/stats/__init__.py", line 334, in <module>
from .stats import *
File "/usr/local/lib/python2.7/dist-packages/scipy/stats/stats.py", line 181, in <module>
import scipy.special as special
File "/usr/local/lib/python2.7/dist-packages/scipy/special/__init__.py", line 548, in <module>
from .basic import *
File "/usr/local/lib/python2.7/dist-packages/scipy/special/basic.py", line 17, in <module>
from . import orthogonal
File "/usr/local/lib/python2.7/dist-packages/scipy/special/orthogonal.py", line 90, in <module>
from scipy import linalg
File "/usr/local/lib/python2.7/dist-packages/scipy/linalg/__init__.py", line 159, in <module>
from .misc import *
File "/usr/local/lib/python2.7/dist-packages/scipy/linalg/misc.py", line 5, in <module>
from . import blas
File "/usr/local/lib/python2.7/dist-packages/scipy/linalg/blas.py", line 145, in <module>
from scipy.linalg import _fblas
ImportError: /usr/local/lib/python2.7/dist-packages/scipy/linalg/_fblas.so: undefined symbol: clange_
Installing from source solved the issue.
First download the numpy and scipy tarballs.
Then locate the BLAS and LAPACK *.so files on my machine. I found them in /usr/lib/. If they are not there you can install them. I used the standard Ubuntu finder to locate them:
find -iname 'libblas.so'
find -iname 'liblapack.so'
So I set some environment variables for the installation.
export BLAS=/usr/lib/libblas.so
export LAPACK=/usr/lib/liblapack.so
Then I downloaded the source tarballs of numpy and scipy, untarred the tarball and then installed by cd into the install directories and
python setup.py build
sudo python setup.py install
NOTE: You may want to specify the install directory.
Comments welcome. Perhaps there is a better way.
The problem is related to Scipy missing proper reference to LAPACK. I followed the instructions suggested by #jtorca and found that you don't even need to install via tarballs. For me, the following did the trick:
apt-get install libopenblas-dev liblapack-dev
export BLAS=/usr/lib/libblas.so
export LAPACK=/usr/lib/liblapack.so
pip install numpy
pip install scipy

What should I modify to solve the "No module named _sqlite3" error message?

I installed ATpy-0.9.7 on my pc successfully and I also have the Python version of "2.7.5".
But when I import atpy I get the following error message:
>>> import atpy
ERROR: ImportError: No module named _sqlite3 [unknown]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "atpy/__init__.py", line 1, in <module>
from .basetable import Table, TableSet, VectorException
File "atpy/basetable.py", line 15, in <module>
from . import registry
File "atpy/registry.py", line 186, in <module>
from . import sqltable
File "atpy/sqltable.py", line 10, in <module>
from . import sqlhelper as sql
File "atpy/sqlhelper.py", line 11, in <module>
import sqlite3
File "/export/aibn84_2/zahra/lib/Python-2.7.5/lib/python2.7/sqlite3/__init__.py", line 24, in <module>
from dbapi2 import *
File "/export/aibn84_2/zahra/lib/Python-2.7.5/lib/python2.7/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: No module named _sqlite3
I also installed db_sqlite3.egg-info. I don't know why this error message occurs!
I installed again th python2.7.5 with the following command :
./configure --prefix=$PYTHONPATH
but I also get this error after executing make:
Python build finished, but the necessary bits to build these modules were not found:
_bsddb _sqlite3 bsddb185
dbm dl gdbm
imageop sunaudiodev
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
How could I run configure in order to install required C libraries?
If you are using a self built version of Python you need to ensure that both the base and the development sqllite3 packages are installed on your system before building Python.
If they are not and, as you said, you do not have superuser privileges, you can download and build sqlite locally, and get your Python build to use that version. This blog post describes how.
According to this question
How can I install sqlite3 to Python?
...you shouldn't have to install anything to get sqlite3 for python. Before I could import atpy I did have to install astropy (which was quite involved). After I did that, everything worked.