Category Archives: Python

Importerror: no module named yaml solution [How to Solve]

problem : I got the “ImportError: No module named yaml ” error when I attempted  to install NLTK toolkit to my ubuntu system.

solution:

yaml library for python seems to not be installed on your system.

On ubuntu system just do a :

sudo apt-get install python-yaml

On windows

easy_install python-yaml

easy_install rosinstall

 

When installing under the window, it may not have its own installation easy_install, we need to install it manually

First download the easy_install installation package, download address:
http://pypi.python.org/pypi/setuptools

Find ez_setup.py on the page and download it and execute it

It is troublesome to download  PyYAML-3.10.win32-py2.7.exe directly

 

[Solved] ImportError: No module named tensorflow

surroundings:

python3.5.3+pycharm2018.2EAP

Problem Description:

Pycharm compilation error

ImportError: No module named tensorflow

Solution:

tensorflow is not installed correctly and needs to be uninstalled and reinstalled,

cmd script input: pip uninstall tensorflow

At the same time, it is best to unload some of the attached libraries (tensorboard, tensorflow-estimator and other tensorflow-related libraries)

The same code with pip uninstall xx

Pay attention to a problem here:

The installed tensorflow version must match the python version, here is a reference:

 

Corresponding to python3.5.3, I installed tensorflow1.5.0, pay attention not to install to tensorflow2.0.0 version, otherwise it will report an error:

could not find a version that satisfies the requrement

After the installation is complete, compile and pass.

 

Solution of import Cafe error reporting in Python command line

1.ImportError: No module named skimage.io

>>> import caffe
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
File “caffe/__init__.py”, line 1, in <module>
from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver, NCCL, Timer
File “caffe/pycaffe.py”, line 15, in <module>
import caffe.io
File “caffe/io.py”, line 2, in <module>
import skimage.io
ImportError: No module named skimage.io

Solution:

Lack of skimage toolbox

pip install scikit-image

 

2.ImportError: dynamic module does not define module export function (PyInit__caffe)

>>> import caffe
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
File “/home/wangxiao/Downloads/project/caffe-master/python/caffe/__init__.py”, line 1, in <module>
from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver
File “/home/wangxiao/Downloads/project/caffe-master/python/caffe/pycaffe.py”, line 13, in <module>
from ._caffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, \
ImportError: dynamic module does not define module export function (PyInit__caffe)
>>>


I found that Python 3.5 is the cause, because higher versions of Python and caffe are not necessarily compatible.

The official caffe website (http://caffe.berkeleyvision.org/) also suggests that caffe 2.7 is only better supported; for other versions, you need to figure it out yourself.

 

3.ImportError: No module named google.protobuf.internal

Solution:

sudo pip install protobuf

 

4.ImportError: No module named caffe

Solution: Add the python directory under the caffe directory to the environment variables

exportPYTHONPATH=/work/project/caffe/python:$PYTHONPATH

 

[Solved] pip install ipython error: ‘ImportError: No module named shutil_get_terminal_size’

Content of error report

ipython
Traceback (most recent call last):
  File "/usr/local/bin/ipython", line 7, in <module>
    from IPython import start_ipython
  File "/usr/local/lib/python2.7/site-packages/IPython/__init__.py", line 48, in <module>
    from .core.application import Application
  File "/usr/local/lib/python2.7/site-packages/IPython/core/application.py", line 25, in <module>
    from IPython.core import release, crashhandler
  File "/usr/local/lib/python2.7/site-packages/IPython/core/crashhandler.py", line 28, in <module>
    from IPython.core import ultratb
  File "/usr/local/lib/python2.7/site-packages/IPython/core/ultratb.py", line 128, in <module>
    from IPython.utils.terminal import get_terminal_size
  File "/usr/local/lib/python2.7/site-packages/IPython/utils/terminal.py", line 22, in <module>
    from backports.shutil_get_terminal_size import get_terminal_size as _get_terminal_size
ImportError: No module named shutil_get_terminal_size

Solution:

Annotate this line
from backports.shutil_get_terminal_size import get_terminal_size as _get_terminal_size
to:
from shutil_backports import get_terminal_size as _get_terminal_size

It works

ImportError No module named setuptools [How to Solve]

 


# wget "https://bitbucket.org/pypa/setuptools/get/default.tar.gz#egg=setuptools-dev" --no-check-certificate

# tar -xzvf default.tar.gz

# cd pypa-setuptools-eb92fc5071bf //depends on the name of your unpacking directory

# python setup.py install

After the installation is complete, just execute your installer command (python setup.py install).

Python3 ImportError: No module named _ssl [How to Solve]

 

The system does not have openssl, manually install openssl
1.Download openssl from http://www.openssl.org/source/openssl-1.0.2a.tar.gz
2.Install.
tar -xzvf openssl-1.0.2a.tar.gz
. /config --prefix=/usr/local --openssldir=/usr/local/openssl
make && make install
 
3. Find the include directory in the /usr/local directory
Find the path /usr/local/include, which will be used in the next steps
There are openssl files under this directory
[root@Linux local]# pwd
/usr/local
[root@Linux local]# ll 
drwxr-xr-x. 2 root  root 4096 11月 13 13:59 bin
drwxr-xr-x. 3 root  root 4096 11月 13 13:59 include
drwxr-xr-x. 2 root  root 4096 11月  1 2011 lib
drwxr-xr-x. 4 root  root 4096 11月 13 13:59 lib64
drwxr-xr-x. 2 root  root 4096 11月  1 2011 libexec
drwxr-xr-x. 2 root  root 4096 11月  1 2011 sbin
 
 
4.In the python3.x source file, find the Setup.dist file and modify it as follows so that the openssl library you just installed can be found when you compile Python
1) Find the SSL related configuration
#SSL=/usr/local/ssl
#_ssl _ssl.c \
#        -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
#        -L$(SSL)/lib -lssl -lcrypto
 
2) (Since openssl is installed in the lib64 and include directories in the /usr/local directory, not in the /usr/local/ssl directory,) remove the comments and modify the path as follows
SSL=/usr/local
_ssl _ssl.c \
        -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
        -L$(SSL)/lib64 -lssl -lcrypto

5 To re-install and compile python 3.x
. /configure --prefix=/usr/local/xxxx
make && make install

6 Try to see if it is available

[root@iZbp1 Python-3.6.5]# python3
Python 3.6.5 (default, Mar 22 2019, 11:36:59) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>> 

[Solved] No module named extern.six.moves

 

C:\Users\Qin>pip install setuptools
Collecting setuptools
  Downloading http://mirrors.aliyun.com/pypi/packages/3b/7e/293d19ccd106119e35db4bf3e111b1895098f618b455b758aa636496cf03/setuptools-28.8.0-py2.py3-none-any.whl (472kB)
    100% |████████████████████████████████| 481kB 6.4MB/s
Installing collected packages: setuptools
Successfully installed setuptools-28.8.0

C:\Users\Qin>pip install requests[socks]
Requirement already satisfied: requests[socks] in e:\python\lib\site-packages
Collecting PySocks!=1.5.7,>=1.5.6; extra == "socks" (from requests[socks])
  Downloading http://mirrors.aliyun.com/pypi/packages/03/a5/957346ba692216cc00e8146fb1a5da0854f8320d7eb073b1cfcb7ad977b5/PySocks-1.5.6.tar.gz
Could not import setuptools which is required to install from a source distribution.
Traceback (most recent call last):
  File "e:\python\lib\site-packages\pip\req\req_install.py", line 387, in setup_py
    import setuptools  # noqa
  File "e:\python\lib\site-packages\setuptools\__init__.py", line 10, in <module>
    from setuptools.extern.six.moves import filter, filterfalse, map
  File "e:\python\lib\site-packages\setuptools\setuptools\__init__.py", line 11, in <module>
    from setuptools.extension import Extension
  File "e:\python\lib\site-packages\setuptools\extension.py", line 7, in <module>
    from setuptools.extern.six.moves import map
ImportError: No module named extern.six.moves

I tried it on the Internet

pipinstall-U setuptools

I’ve also tried to reload setup tools with the command. The problem remains

Finally, you can go to X:: – Python, lib, site packages, delete two related folders of setup tools and one of six-1.10.0, then re install setup tools, and then install PIP install requests [socks], and everything will be OK

Importerror: no module named BS4 error resolution

Preface: Graduation thesis plans to use Python as a crawler to crawl some data, and recently started to get started with Python;

I encountered a problem while studying. I installed Python according to the article I read, and configured the corresponding environment (using the window system), and used the pycharm editor to write Python (this software is very convenient to run Python, and install the libraries needed for Python. It’s also very simple).

After installing the requests and BeautifulSoup libraries, I started to crawl a local html. At the beginning, I quoted from bs4 import BeautifulSoup, but I kept reporting ImportError: No module named bs4 at the end ;

 

After checking some information, the problem was solved smoothly;

Solution:

An ImportError: No module named bs4error is displayed during runtime , meaning that the module named Beautifulsoup4 was not found.

Write about how Python installs modules:

1. Download the BS4 module:

http:/ /www.crummy.com/software /BeautifulSoup/bs4/download/ 4.3/beautifulsoup4- 4.3. 2.tar.gz

2. Unzip it to the root directory under the Python installation directory:

3. Run cmd and enter the decompressed directory (if Python is installed in the C drive by default, after opening cmd, you can use the cd … statement to return to the root directory first, and then enter Python27\beautifulsoup4-4.3.2 )

4. After entering Python27\beautifulsoup4-4.3.2 , install the BS4 module:

 

It can be used after installation;