Tag Archives: python

In Python, import XXX does not report an error, but in IPython (Jupiter notebook)

When importing Sklearn from Jupyter Notebook, the following error is reported

But I have installed it before; It does not report errors on the Python command line. Then Baidu checked the data, but did not find a similar situation. I print the path in Python and in IPython. I print the path in Python and I print the path in IPython.

'D:\\python\\Anaconda3\\envs\\v2\\python35.zip',

'D:\\python\\Anaconda3\\envs\\v2\\DLLs',

'D:\\python\\Anaconda3\\envs\\v2\\lib',

'D:\\python\\Anaconda3\\envs\\v2',

'C:\\Users\\mtl\\AppData\\Roaming\\Python\\Python35\\site-packages',

'D:\\python\\Anaconda3\\envs\\v2\\lib\\site-packages'

Print out the path in IPython as follows:

'D:\\python\\Anaconda3\\envs\\v2\\python35.zip', 
'D:\\python\\Anaconda3\\envs\\v2\\DLLs', 
'D:\\python\\Anaconda3\\envs\\v2\\lib', 
'D:\\python\\Anaconda3\\envs\\v2', 
'C:\\Users\\mtl\\AppData\\Roaming\\Python\\Python35\\site-packages', 
'D:\\python\\Anaconda3\\envs\\v2\\lib\\site-packages', 
'D:\\python\\Anaconda3\\envs\\v2\\lib\\site-packages\\IPython\\extensions', 
'C:\\Users\\mtl\\.ipython'

C:\\Users\ MTL \\.ipython: C:\\Users\ MTL \\.ipython: C:\\Users\\ MTL \\.ipython: C:\\Users\\ MTL \\
Summary: I think because the last folder is empty, the previous files will be flushed out, but I check the information: when looking for the module (model), it will follow the path to find, if found, it will jump out. This interpretation is in conflict here, but also hope to understand this part of the god together to resolve

Solve Python error Unicode error ‘UTF-8’

The complete error message is shown below:

Not to read the error principle, but the solution is as follows:
Open the error file (pcacode.py in this case) using Notepad ++ (which is the editor I always use), find the encoding option in the menu bar, select UTF-8, save it, and run the Python code again so it doesn’t report any errors.

Another solution, which I haven’t tried, is the following:

import codecs
codecs.open('filename',encoding='uft-8')

Python’s json.loads Invalid control character

Preface:
Invalid control character at: line 35 column Invalid control character at: line 35 column Sorrow of mulberry
Gilmar: 1.
This is a call to Baidu map query interface code, using Python’s most original JSON parsing module, using JSON.loads parsing data
debug first: go to the web page directly call the interface, return data looks good
bug second: Using interface debugging tools postman to check the data, there is something wrong with this, the following

reason, although there was something wrong with prompt, but look not to come out from the return to the field, and went to the web site to see the return data,

as if there’s an odd character
so basic sure return a string parsing error
wrong third department: there is a problem to find baidu
2. To

json.loads(s=string, strict=False)
on. loads(s=string, strict=False)
json. Loads (s=string, strict=False)

Error in testing keras


nning Keras under Python is reporting an error — it tells me that one way to fix this problem is to uninstall Numpy repeatedly until I can’t find it, and then reinstall this version. Installation keras
no problem, baidu, a lot of reasons, all have been adjusted, still not solve the
I finally find a suitable way to
find their numpy location
below is I save position (for reference only, everyone is different)

where will use the red pen circle below are deleted, then reinstall the


this is solved!

Syntax error: invalid character in identifier

Invalid character in identifier: SyntaxError: Invalid character in identifier
Online a search answer, said that there is a Chinese state of parentheses, this is indeed a reason;
Another reason is that there is a space at the end of the code. When the space is removed, the code runs decisively

Python error: typeerror: ‘Int’ object is not subscriptable

Check the line where the error is reported, which is usually an integer with a subscript:
Such as:

a = 4
c=a[2]

Error: line 2, in <; module>
c = a [2]
TypeError: ‘int’ object is not subscriptable
Or a more complicated one: two dimensions
 

a = [1,2,3,4]
c=a[2][2]

It’s a one-dimensional array, but you take an array and then you subscript it, same problem.

Python error: command error out with exit status 1:

Update 2020.08.24: It seems that the reason for this is that Python 2 and Python 3 have different default encoding formats.
Python 2 is GBK and Python 3 is UTF-8. Some older packages can cause coding problems when installed.


Because PyCharm recently pops up RELP Communications all the time, it affects the efficiency of the code.
REPL (Read-Eval-Print Loop), which translates as “read-evaluation-output” Loop, is a simple, interactive programming environment.
Sounds useful, so I want to PIP the REPL directly in PyCharm.

Error result:
ERROR: Command errored out with exit status 1:

 
The main error is shown in the last few lines:
UnicodedecodeError: ‘GBK’ codec can’t decode byte 0xa6 in position 1246: illegal multibyte sequence
—————————————-
ror: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

Positioning problems:
UnicodeDecodeError, indicating an encoding problem.
Specifically, on lines 10 and 17 of the setup.py file, the read file is encoded as GBK, not UTF-8, so the error prevents installation.


Update the successful solution:
Because you cannot use Project Interpreter in PyCharm.
Solution: download the source code package, make code changes and then install.
1. Locate the file of the original Package and find the line that reported the error.
REPL official address is: https://github.com/mbr/repl. View the source code of the setup file that reported the error.

Location problem: the source code does not specify the open encoding, so the default is GBK encoding.
Error source code:

def read(fname):
    return open(os.path.join(os.path.dirname(__file__), fname)).read()

 
2. After downloading the original package file, unpack it and find the setup.py file. Change this line in the file, add encoding=’utf-8′, save it and package it as a new installation package.
Modified code:

def read(fname):
    return open(os.path.join(os.path.dirname(__file__), fname),encoding='utf-8').read()

 
3. Enter PIP install repl-1.0.tar.gz and install with the new package. Success!


This problem bothered me for a week, but it turned out that the solution was very simple!
The most important thing to solve the problem is to locate the cause of the error, and then find a solution step by step according to the reason.

Python combined with Matplotlib to add button

This article reprinted from https://www.it610.com/article/1282212275846922240.htm
if you have offended, please contact me
I looked for Matplotlib button for a long time before I found something I could understand. I don’t know if it was too simple, so no one wrote it.
ttonAxe = PLT.axes ([0.94, 0.03, 0.03, 0.03]) u>to set the position of the button.
tton1 = Button(buttonAxe, 'p2',color='khaki', overcolor='yellow') i>ed to create the Button and to set the color and the color of the Button when the mouse is over the Button.
third line tton1.on_clicked (show2) s>the function triggered after the button is clicked.
in addition to write after click the button to trigger functions should pay attention to write the event in the brackets, such as def show2 (event) :

buttonaxe = plt.axes([0.94, 0.03, 0.03, 0.03])
button1 = Button(buttonaxe, 'p2',color='khaki', hovercolor='yellow')
button1.on_clicked(show2)

Package summary of installing python with CONDA

Install Python with Conda package summary ## title
If you want to find which package, go to the official website and download it directly to this directory (my directory location)

CD C:\ProgramData\Anaconda3\Lib
\ ProgramData\Anaconda3\Lib
\
PIP install torchvision-0.1.8-py2.py3-none-any.whl
p install torchvision-0.1.8-py2.py3-none-any.whl
PIP install torchvision-0.1.8-py2.py3-none-any.whl
PIP install torchvision-0.1.8-py2.py3-none-any.whl . (here torchvision 0.1.8 – py2 py3 – none – any. WHL, is my at https://pypi.org/project/torchvision/0.1.8/#files to download python library)
this time in the CMD import torchvision went wrong, but in the anaconda in the prompt is correct.
Everything will be all right!