Category Archives: Python

ImportError: No module named caffe.proto [How to Solve]

 

When training SSD model based on cafe with our own data, we need to convert the image data into LMDB format. The script file used is create provided in SSD source code_ Data.sh (specific location is in $Cafe)_ ROOT/data/VOC0712/create_ Take a copy of it and give it its own name, such as create_ scenetext_ Data. Sh, and then modify the path according to your actual situation

After modification, execute the command shcreate_ Data.sh, the following error may appear:

[lisiqi@l22-240-142 caffe]$ sh create_lmdbdata_scenetext.sh 
Traceback (most recent call last):
  File "/data/home/lisiqi/my_SSD/caffe/scripts/create_annoset.py", line 7, in <module> from caffe.proto import caffe_pb2 ImportError: No module named caffe.proto Traceback (most recent call last): File "/data/home/lisiqi/my_SSD/caffe/scripts/create_annoset.py", line 7, in <module> from caffe.proto import caffe_pb2 ImportError: No module named caffe.proto

Possible reason: in this case, the path of Python related content in cafe is not added to the compile path of Python

Solution:

Execute the order

export PYTHONPATH=$CAFFE_ROOT/python:$PYTHONPATH

Of which, $Cafe_ Root is the path to download SSD source code. For example, mine is/data/home/lisiqi/my_ SSD/caffe

Note: the above method is only one-time, run create again next time_ scenetext_ Data. Sh, you need to do the above operation

[Solved] ImportError: cannot import name pywrap_tensorflow

 

Problem: importing tensotflow in Python cli is normal, but the following error is given in jupyter:

ImportError: cannot import name pywrap_tensorflow

Importing tensorflow in jupyter notebook (Not working Error):

import tensorflow as tf

ImportErrorTraceback (most recent call last)
 in ()
      2 import cv2 as cv2  3 from PIL import Image ----> 4 import tensorflow as tf  5 #'/home/ubuntu/.local/lib/python2.7/site-packages/tensorflow' /home/ubuntu/.local/lib/python2.7/site-packages/tensorflow/__init__.py in ()  21 from __future__ import print_function  22 ---> 23 from tensorflow.python import *  24  25 /home/ubuntu/.local/lib/python2.7/site-packages/tensorflow/python/__init__.py in ()  47 _default_dlopen_flags = sys.getdlopenflags()  48 sys.setdlopenflags(_default_dlopen_flags | ctypes.RTLD_GLOBAL) ---> 49 from tensorflow.python import pywrap_tensorflow  50 sys.setdlopenflags(_default_dlopen_flags)  51 ImportError: cannot import name pywrap_tensorflow


Importing tensorflow in CLI python (Working):

$ python

Python 2.7.12 (default, Jul 1 2016, 15:12:24)
[GCC 5.4.0 20160609] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.

>>> import tensorflow
>>> import tensorflow as tf
>>> print(tf)
<module ‘tensorflow’ from ‘/home/ubuntu/.local/lib/python2.7/site-packages/tensorflow/__init__.pyc’>
>>> help(tf)

>>> print tf.__version__
0.11.0rc2
>>> print tf.__path__
[‘/home/ubuntu/.local/lib/python2.7/site-packages/tensorflow’]

Issue investigation:

Check the location of the tensorflow package:

$ls/home/ubuntu/.local/lib/python2.7/site-packages/tensorflow/
contrib core examples includeinit.pyinit.pyc models python tensorboard tools

Check the location of the jupyter

$ ps -ef | grep jupyter
ubuntu 1347 1 0 Nov11 ?00:00:46 /usr/bin/python /usr/local/bin/jupyter-notebook -no-browser -ip=* -port=8888

Location of other python packages:

>> import sklearn
>>> print(sklearn.__path__)
[‘/home/ubuntu/.local/lib/python2.7/site-packages/sklearn’]
>>> import mxnet
>>> print(mxnet.__path__)
[‘/usr/local/lib/python2.7/dist-packages/mxnet-0.7.0-py2.7.egg/mxnet’]

Solution:

If you have installed tensorflow while jupyter is running, importing tensorflow will not work in jupyter (check if it works on python CLI).You just need to Restart jupyter notebook and it should work.

If you have problem in both jupyter and python CLI, then you just need to start jupyter from other location.

How to install PIP in no module named setuptools

ImportError: No module named setuptools [How to Solve]

wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz –no-check-certificate

tar zxvf setuptools-0.6c11.tar.gz
cd setuptools-0.6c11
python setup.py build
python setup.py install

pip install

wget--no-check-certificatehttps://github.com/pypa/pip/archive/1.5.5.tar.gz

Note: when WGet gets HTTPS: – – no check certificate should be added

tarzvxf1.5.5.tar.gz#unzip file cdpip-1.5.5/
pythonsetup.pyinstall

OK, so pip is installed

Let’s install requests

pipinstallrequests

 

ImportError: No module named pkg_resources [How to Solve]

This problem is usually caused by PIP execution after upgrading to python2.7. The solution is to re install PIP in the python2.7 environment. The steps are as follows:

System: centos7 (it is recommended to use centos7, 6, if you need to upgrade too many libraries, glibc also needs to upgrade, if you don’t upgrade well, it will be useless)

First type of installation:
yum install gcc python-setuptools python-devel
easy_install pip

If the above does not work, use the following method

1. Install distribute

wget https://pypi.python.org/packages/source/d/distribute/distribute-0.7.3.zip –no-check-certificate
unzip distribute-0.7.3.zip
cd distribute-0.7.3
python setup.py install

2. Install setuptool
https://pypi.python.org/pypi/setuptools Download the latest version
Solve and enter the directory
python setup.py install

3. Install pip
easy_install pip

4. If the installation process of pip report ImportError: No module named extern exception

https://pypi.python.org/pypi/extern Download the latest extern and install it and try again

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

 

How to Solve Python Error: “HTTP Error 403: Forbidden”

Question:

When the following statement is executed

1 def set_IPlsit():
2     url = 'https://www.whatismyip.com/'
3     response = urllib.request.urlopen(url)
4     html = response.read().decode('utf-8')

The following exception occurred:

C:\Users\54353\AppData\Local\Programs\Python\Python36\python.exe "C:/Users/54353/PycharmProjects/untitled/爬虫/图片 - 某网站.py"
Traceback (most recent call last):
  File "C:/Users/54353/PycharmProjects/untitled/crawler/pic.py", line 100, in <module>
    ip = set_IPlsit2()
  File "C:/Users/54353/PycharmProjects/untitled/crawler/pic.py", line 95, in set_IPlsit2
    response = ure.urlopen(url)
  File "C:\Users\54353\AppData\Local\Programs\Python\Python36\lib\urllib\request.py", line 223, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Users\54353\AppData\Local\Programs\Python\Python36\lib\urllib\request.py", line 532, in open
    response = meth(req, response)
  File "C:\Users\54353\AppData\Local\Programs\Python\Python36\lib\urllib\request.py", line 642, in http_response
    'http', request, response, code, msg, hdrs)
  File "C:\Users\54353\AppData\Local\Programs\Python\Python36\lib\urllib\request.py", line 570, in error
    return self._call_chain(*args)
  File "C:\Users\54353\AppData\Local\Programs\Python\Python36\lib\urllib\request.py", line 504, in _call_chain
    result = func(*args)
  File "C:\Users\54353\AppData\Local\Programs\Python\Python36\lib\urllib\request.py", line 650, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden

Process finished with exit code 1

analysis:

The reason for the above exception is that if you open a URL in urllib.request.urlopen mode, the server will only receive a simple request for accessing the page, but the server does not know the browser, operating system, hardware platform and other information used to send the request, and the request without such information is often abnormal access, such as crawler

In order to prevent this kind of abnormal access, some websites will verify the user agent in the request information. If the user agent is abnormal or does not exist, the request will be rejected

Solution:

Add the user agent to the request, and the code is as follows

1 headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0'}  
2 req = urllib.request.Request(url=chaper_url, headers=headers)  
3 urllib.request.urlopen(req).read()

python from scipy.misc import imread:ImportError: cannot import name imread

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

from scipy.misc import imread
error: Import error: cannot import name imread
error

The solution is as follows:
1. Install pilot (imread depends on pilot)
2. Check whether pilot and SciPy are installed in the same path
3. Other

However, these can’t solve my problems. Finally, I saw the following method in a comment:
downgrade SciPy to Version 1.2.1 (PIP install SciPy = = 1.2.1)

Pro test is available
however, there will be such a red letter (which does not affect the use and output results)

which means that imread will be removed after scipy1.2.0, which is also the reason why it can not be used before
at the same time, It is also suggested that imageio. Imread can be used to replace imread
that is:
1. PIP install imageio
2. Import imageio
3. Img = imageio. Imread (‘xx. PNG ‘)
1

[summary]
1. Without using SciPy, using imageio to call imread
2. Using scipy1.2.1

In addition: before installing a third-party library, you must remember to install numpy + MKL , and then install SciPy, pilot and other third-party libraries. Many third-party libraries rely on the installation of numpy + MKL before they work

undertake MATLAB, Python and C + + programming, machine learning, computer vision theory implementation and guidance, undergraduate and master can, salted fish trading, professional answer please go to know, for details, please contact QQ number 757160542, if you are the one

This article shares in the blog “Yu Xiaoyong” (CSDN).

[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 ‘\ \’

Mac Python3 Conda Pytorch Error: libc++abi.dylib: terminating with uncaught exception of type NSException

The example of running neural network in MAC 10.14/conda/python 3.7 environment is wrong

2019-03-19 17:07:55.982 python[1556:126911] -[NSApplication _setup:]: unrecognized selector sent to instance 0x7fd5a5811270
2019-03-19 17:07:55.988 python[1556:126911] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSApplication _setup:]: unrecognized selector sent to instance 0x7fd5a5811270'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff3c94643d __exceptionPreprocess + 256
    1   libobjc.A.dylib                     0x00007fff68853720 objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff3c9c3255 -[NSObject(NSObject) __retain_OA] + 0
    3   CoreFoundation                      0x00007fff3c8e5ad0 ___forwarding___ + 1486
    4   CoreFoundation                      0x00007fff3c8e5478 _CF_forwarding_prep_0 + 120
    5   libtk8.6.dylib                      0x00000001334ee31d TkpInit + 413
    6   libtk8.6.dylib                      0x000000013344617e Initialize + 2622
    7   _tkinter.cpython-37m-darwin.so      0x000000010727aa0f _tkinter_create + 1183
    8   python                              0x0000000105b028b6 _PyMethodDef_RawFastCallKeywords + 230
    9   python                              0x0000000105c3fba2 call_function + 306
    10  python                              0x0000000105c3d852 _PyEval_EvalFrameDefault + 46114
    11  python                              0x0000000105c311fe _PyEval_EvalCodeWithName + 414
    12  python                              0x0000000105b01587 _PyFunction_FastCallDict + 231
    13  python                              0x0000000105b83c31 slot_tp_init + 193
    14  python                              0x0000000105b8dc01 type_call + 241
    15  python                              0x0000000105b02283 _PyObject_FastCallKeywords + 179
    16  python                              0x0000000105c3fc35 call_function + 453
    17  python                              0x0000000105c3d946 _PyEval_EvalFrameDefault + 46358
    18  python                              0x0000000105b02075 function_code_fastcall + 117
    19  python                              0x0000000105c3fb27 call_function + 183
    20  python                              0x0000000105c3d852 _PyEval_EvalFrameDefault + 46114
    21  python                              0x0000000105c311fe _PyEval_EvalCodeWithName + 414
    22  python                              0x0000000105b01587 _PyFunction_FastCallDict + 231
    23  python                              0x0000000105b054a2 method_call + 130
    24  python                              0x0000000105b02ef2 PyObject_Call + 130
    25  python                              0x0000000105c3da9d _PyEval_EvalFrameDefault + 46701
    26  python                              0x0000000105c311fe _PyEval_EvalCodeWithName + 414
    27  python                              0x0000000105b02783 _PyFunction_FastCallKeywords + 195
    28  python                              0x0000000105c3fb27 call_function + 183
    29  python                              0x0000000105c3d88d _PyEval_EvalFrameDefault + 46173
    30  python                              0x0000000105b02075 function_code_fastcall + 117
    31  python                              0x0000000105c3fb27 call_function + 183
    32  python                              0x0000000105c3d88d _PyEval_EvalFrameDefault + 46173
    33  python                              0x0000000105c311fe _PyEval_EvalCodeWithName + 414
    34  python                              0x0000000105b02783 _PyFunction_FastCallKeywords + 195
    35  python                              0x0000000105c3fb27 call_function + 183
    36  python                              0x0000000105c3d88d _PyEval_EvalFrameDefault + 46173
    37  python                              0x0000000105c311fe _PyEval_EvalCodeWithName + 414
    38  python                              0x0000000105b02783 _PyFunction_FastCallKeywords + 195
    39  python                              0x0000000105c3fb27 call_function + 183
    40  python                              0x0000000105c3d852 _PyEval_EvalFrameDefault + 46114
    41  python                              0x0000000105b02075 function_code_fastcall + 117
    42  python                              0x0000000105c3fb27 call_function + 183
    43  python                              0x0000000105c3d88d _PyEval_EvalFrameDefault + 46173
    44  python                              0x0000000105c311fe _PyEval_EvalCodeWithName + 414
    45  python                              0x0000000105c94760 PyRun_FileExFlags + 256
    46  python                              0x0000000105c93bd7 PyRun_SimpleFileExFlags + 391
    47  python                              0x0000000105cc17bf pymain_main + 9583
    48  python                              0x0000000105ad4bbd main + 125
    49  libdyld.dylib                       0x00007fff69921085 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Abort trap: 6

To solve this problem, run the following command:

$ mkdir -p ~/.matplotlib
$ echo "backend: TkAgg" > ~/.matplotlib/matplotlibrc

And then it worked

The specific reasons are as follows: https://github.com/PAHdb/AmesPAHdbPythonSuite/issues/1