Tag Archives: Python

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

 

Windows Python Install: requires numpy+mkl & ImportError: cannot import name NUMPY_MKL

 

Recently, I wrote an article about “installation and use of Microsoft open source distributed high performance GB framework lightgbm”. Some partners encountered problems when installing Python environment. I personally tried to install it, and I really encountered a lot of problems“ After the problem of “installing the SciPy Library of Python under Windows 7” was solved, we encountered “importerror: cannot import name numpy”_ MKL. As follows:

[plain]

view plain

copy

D:\LightGBM\LightGBM\examples\python-guide> pythonsimple_ example.py

Traceback(mostrecentcalllast):

File”simple_ example.py”,line4,in< module>

importlightgbmaslgb

File”D:\Python27\lib\site-packages\lightgbm-0.1-py2.7.egg\lightgbm\__ init__. p

y”,line9,in< module>

from.basicimportDataset,Booster

File”D:\Python27\lib\site-packages\lightgbm-0.1-py2.7.egg\lightgbm\basic.py”,

line15,in< module>

importscipy.sparse

File”D:\Python27\lib\site-packages\scipy\__ init__. py”,line61,in< module>

fromnumpy._ distributor_ initimportNUMPY_ MKL#requiresnumpy+mkl

ImportE rror:cannotimportnameNUMPY_ MKL

Why is there such a problem

Reference“ http://stackoverflow.com/questions/37267399/importerror-cannot-import-name-numpy-mkl ”What I’m saying is

Because my “SciPy” is installed with “. WHL” file according to the method in “installation of Python’s SciPy Library under Windows 7”, and “numpy” is installed with “PIP install numpy” command

In fact, I used the “PIP install numpy” command to install. In fact, I downloaded a “. WHL” file, which is different from the download source of “SciPy”, but it doesn’t work

What to do?What to do

Unload numpy with the command “PIP install numpy” and MKL with the command “PIP install MKL”

Using the same source as “SciPy”, from“ http://www.lfd.uci.edu/~gohlke/pythonlibs/ ”Download the installation file of “numpy” (find the corresponding version)

Then use the command to install: PIP installnumpy {1.14.2 + MKL} cp35} cp35m} win_ AMD64. WHL

The problem is solved

How to Solve Python Start Error: IDLE’s subprocess didn’t make conne…

Question.
Prompt Error.
IDLE’s subprocess didn’t make connection.Either IDLE can;t

start a subprocess or personal firewall software is blocking

the connection

That usually means that your firewall is blocking IDLE, so

enable it in your firewall. If that doesnt work, do this to fix

it (with some disavantages):

Open C:/Python24/Lib/idlelib/PyShell.py

change
use_subprocess = True

to

use_subprocess = False

Also delete PyShell.pyc

 

The error and installation method of import CV2 in Python

Don’t panic in case of data tilt, teach you to easily obtain the slope of table tilt>>>

Reference link: https://blog.csdn.net/yuanlulu/article/details/79017116

From x86_ Import CV2 (opencv4.1) in 64 + Ubuntu 18.04 + Python 3.5, encountered the following error:

ImportError: libSM.so.6: cannot open shared object file: No such file or directory

ImportError: libXrender.so.1: cannot open shared object file: No such file or directory

ImportError: libXext.so.6: cannot open shared object file: No such file or directory

ImportError: libgthread-2.0.so.0: cannot open shared object file: No such file or directory

Solution:

apt-get update

apt-get install libsm6

apt-get install libxrender1

apt-get install libglib2.0-dev apt-get install libxext-dev

[Solved] Python SyntaxWarning: name ‘xxx’ is assigned to before global declaration

The most common reason for this error is that you’re using multiple global declarations in the same function. Consider this example:

x = 0

def func(a, b, c):
if a == b:
global x
x = 10
elif b == c:
global x
x = 20

If you run this in a recent version of Python, the compiler will issue a SyntaxWarning pointing to the beginning of the func function.

Here’s the right way to write this:

x = 0

def func(a, b, c):
global x # <- here
if a == b:
x = 10
elif b == c:
x = 20

Python: json:json.decoder.JSONDecodeError: Invalid control character at: line 2 column 18 (char 19)

1. JSON. Loads (JSON_ Json.decoder.jsondecodeerror: invalid control character at: Line 2 column 18 (char 19)

reason: JSON uses rigorous format by default, which is easy to report when data is transferred across languages

solution: add the parameter strict

json.loads(json_data, strict=False)

2. JSON. Dumps (data) to convert Chinese characters into Unicode

reason: JSON performs character conversion by default

solution: add ensure_ ASCII parameter

json.dumps(data, ensure_ascii=False)

3. JSON. Loads (JSON_ Error: JSON. Decoder. Jsondecodeerror: invalid – escape: Line 1 column 89 (char 88)

Error reason: syntax error

Solutions

Check JSON_ Data data, whether it contains illegal characters, such as backslash ‘\’, change ‘\’ to ‘\ \’

Improper indentation of Python comments results in an indentation error: unexpected indent

Why can’t you stop buying 618?From the technical dimension to explore>>>

def test():
    i=0
'''
aaaaaa
'''
    while i < 5:
    '''
    bbbbbb
    '''        
        print(i)
        i+=1
        
if __name__ == '__main__':
    test()

As mentioned above, improper indentation of Python comments can also lead to an indentation error: unexpected indent. Modify the abbreviation of the note as follows

def test():
    i=0
    '''
    aaaaaa
    '''
    while i < 5:
        '''
        bbbbbb
        '''        
        print(i)
        i+=1
        
if __name__ == '__main__':
    test()

When running Python script, an error is reported: a true sslcontext object is not available

Why can’t you stop buying 618?From the technical dimension to explore>>>

Today, to run a python script in a new environment, we encountered the following error:

/usr/lib/python2.7/site-packages/urllib3/util/ssl_. py:160: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a new……

The error report is related to the security policy. I searched online because of the python Version (using python2.7.5). The solution is to either upgrade the python version or install requests

Based on the principle of minimum influence, it is decided to adopt the latter as follows:

pip install requests[security]

After the installation is completed, run the python script again, and the same error is reported. I tried again

PIP install pyopenssl NDG httpclient pyasn1 (equivalent to installing requests)

After the installation is completed, rerun the python script and report the same error. I think of a common trick upgrade

pip install –upgrade requests[security]

After the installation is completed, run the python script again. As expected, no longer report the error of insure platform warning

Digression: there is no mistake in insure platform warning, but another mistake, cryptographicdecrecation warning, has been reported. The details are as follows:

/usr/lib64/python2.7/site-packages/cryptography/hazmat/primitives/constant_ time.py:26: CryptographyDeprecationWarning: Support for your Python version is deprecated. The next version of cryptography will remove support. Please upgrade to a 2.7.x release that supports hmac.compare_ digest as soon as possible.

utils.DeprecatedIn23

Remind to upgrade the python version, but at this time the script does not involve security, it can be executed normally

Python read CSV file prompt “line contains null byte” error

Open source software supply chain lighting plan, waiting for you>>>

When Python reads a file, it appears_ When CSV. Error: line contains null byte

# -*- coding:utf-8 -*-

import csv

with open(r'E:\abc\web_test\userinfo.csv','rb') as f:
    reader = csv.reader(f)
    rows = [row for row in reader]
    print rows

Error:

D:\Python27\python.exe E:/abc/loop_reader.py
Traceback (most recent call last):
  File "E:/abc/web_test/loop_reader.py", line 7, in <module>
    rows = [row for row in reader]
_csv.Error: line contains NULL byte

Process finished with exit code 1

The error prompt is:_ csv.Error: line contains NULL byte

CSV error, line contains empty bytes

Reason: it is usually because the extension is XLS or xlsx when saving, and changing it to a CSV file is usually a rename

Solution: save it as a. CSV file