Python3 configuration and entry.md

[ TOC]

0 x00 basic configuration####

IDLE shortcut

ALT + p  #Last command executed

(1) Python Shell clear screen method

"""
Clear Window Extension
Add these lines to config-extensions.def

[ ClearWindow]
enable=1
enable_editor=0
enable_shell=1[ClearWindow_cfgBindings]
clear-window=<Control-Key-l>"""

classClearWindow:

 menudefs =[('options',[None,('Clear Shell Window','<<clear-window>>'),]),]
     
 def __init__(self, editwin):
  self.editwin = editwin
  self.text = self.editwin.text
  self.text.bind("<<clear-window>>", self.clear_window2)

  self.text.bind("<<undo>>", self.undo_event)  # add="+" doesn't work

 def undo_event(self, event):
  text = self.text
        
  text.mark_set("iomark2","iomark")
  text.mark_set("insert2","insert")
  self.editwin.undo.undo_event(event)

  # fix iomark and insert
  text.mark_set("iomark","iomark2")
  text.mark_set("insert","insert2")
  text.mark_unset("iomark2")
  text.mark_unset("insert2")
        

 def clear_window2(self, event): # Alternative method
  # work around the ModifiedUndoDelegator
  text = self.text
  text.undo_block_start()
  text.mark_set("iomark2","iomark")
  text.mark_set("iomark",1.0)
  text.delete(1.0,"iomark2 linestart")
  text.mark_set("iomark","iomark2")
  text.mark_unset("iomark2")
  text.undo_block_stop()if self.text.compare('insert','<','iomark'):
   self.text.mark_set('insert','end-1c')
  self.editwin.set_line_and_column()

 def clear_window(self, event):
  # remove undo delegator
  undo = self.editwin.undo
  self.editwin.per.removefilter(undo)

  # clear the window, but preserve current command
  self.text.delete(1.0,"iomark linestart")if self.text.compare('insert','<','iomark'):
   self.text.mark_set('insert','end-1c')
  self.editwin.set_line_and_column()
 
  # restore undo delegator
  self.editwin.per.insertfilter(undo)

(2) Python multi-version coexistence
The way I often use is to add one to the PATH, and the other version does not add to python; but the pain is that each execution needs to specify the absolute path, and when pip downloads, it also needs to be executed in the specified directory;
Solution:

# Python&#39;s own solution
When installing python2.After 7 directly call pip to execute Python2.7 pip,How to solve?
pip3 install xxxx
py -3-m pip install xxxx

# Question 1: Set the Python version opened by right-clicking on the &quot;Edit with IDLE&quot; option under win10.
# solution:
1. Enter regedit at the runtime to enter the registry;
2. Found item[HKEY_CLASSES_ROOT\Python.File\shell\Edit with IDLE\command]3.Double click (default) and change the value to:"C:\Python34\pythonw.exe""C:\Python34\Lib\idlelib\idle.pyw"-e "%1"Can

# Question 2: How to specify double-click to open.py file program?
# Solution: At this time, it is generally useless to modify the &quot;Open Method&quot; of &quot;Properties&quot;, because Python is very willful and there is no way.......

# It still needs to be resolved by modifying the registry.
1. Enter regedit at the runtime to enter the registry;
2. Found item[HKEY_CLASSES_ROOT\Python.File\shell\open\command]3.Double click (default) and change the value to:"C:\Python34\python.exe""%1"%*OK (here I want to double-click to use Python3.4 Open).
4. At the same time C:\Python34;C:\Python34\Scripts are added to the environment variable (right click &quot;this computer&quot;->&quot;Advanced System Settings&quot;->&quot;Environmental Variables(N)...&quot;, modify the PATH variable of the user environment variable).

# Question 3: If Python2 exists in your system at the same time.7 and Python3.4. Then enter Python in the command line mode, the default is to execute Python2.7:
# Because Python itself is set to be compatible in the command line mode
$ python 
$ py -3
C:\Users\Administrator>py -2
Python 2 not found!
Installed Pythons found by py Launcher for Windows
 -3.7-64*

# Additional skills:
When my code needs to use Python2.At 7 o&#39;clock, select execute with the right mouse button.
In the registry: HKEY_CLASSES_ROOT\Python.File\shell\New item in &quot;via Python2.7Run&quot;, then create a new item &quot;command&quot;, set the default value to:"C:\Python27\python.exe""%1"%*Can

WeiyiGeek. Right-click to open

0 x01 pip command

It is recommended to use pip for management of python dependent libraries. If pip is not installed, the following commands can be executed to install:

# General Python environment
wget https://sec.ly.com/mirror/get-pip.py --no-check-certificate && python get-pip.py

# Ubuntu, Kail test
apt-get install python-pip
apt-get install python-setuptools
easy_install pip
pip gevent --upgrade
pip install --upgrade pip

# Note: If the last step is incorrectly executed
[ email protected]:pip install setuptools --no-use-wheel --upgrade

error: Microsoft Visual C++ 14.0 is required. Get it with “Microsoft Visual C++ Build Tools”: https://visualstudio.microsoft.com/downloads/

Python 2.7 requires Microsoft Visual C++ 9.0 library Python 3.6 requires Microsoft Visual C++ 14.0 library

0 x02 Into the pit####

# Solution 1: Install the extension source EPEL first,EPEL(http://fedoraproject.org/wiki/EPEL)It is created by the Fedora community to provide high-quality software packages for RHEL and derivative distributions such as CentOS, Scientific Linux, etc.
# First install the epel extension source:
$ sudo yum -y install epel-release
# Then install pip
$ sudo yum -y install python-pip
 
# Solution 2: If you have not installed pip,You can execute the following command to install:
wget https://sec.ly.com/mirror/get-pip.py --no-check-certificate && python get-pip.py

# Update to the latest version of pip:
$ pip install -U pip
$ python -m pip install --upgrade pip
 workspace> pip
Traceback(most recent call last):
 File "/usr/bin/pip", line 9,in<module>from pip import main
ImportError: cannot import name main

Repair process:

# If compulsory saving under read-only permission will cause file damage, it is recommended to check whether you have permission before modifying the configuration file
$vim /usr/bin/pip

from pip import __main__  #Modify this line
if __name__ =='__main__':  
 sys.exit(__main__._main())#increase__main__._

# Finally save and view
workspace> pip -V              
pip 19.1.1from/home/coding/.local/lib/python2.7/site-packages/pip(python 2.7)

**Question 1: Use pip3 to install Certbot error **
Problem Description:

Command python setup.py egg_info failed with error code 1in/tmp/pip_build_root/cryptography
Storing debug log for failure in/root/.pip/pip.log

Solution:

easy_install -U setuptools
sudo pip3 install certbot

Question 2: The setuptools version is too old and the dependencies cannot be downloaded
Problem Description:

RuntimeError: cryptography requires setuptools 18.5 or newer, please upgrade to a newer version of setuptool

Solution:

pip install --upgrade setuptools

pip command

pip list   #View all dependent packages
pip freeze #View the newly installed packages of the virtual environment
pip install xxx  #Install xxx dependency package

Pypi image acceleration configuration of pip installation module

# temporary use
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package

# Used by default
# Upgrade pip to the latest version(>=10.0.0)After configuration/
pip install pip -U
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U  #If the default source network connection of the above upgrade connection is poor, temporarily use this command to upgrade pip;
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
# Writing to C:\Users\WeiyiGeek\AppData\Roaming\pip\pip.ini

Question 1. ModuleNotFoundError: No module named'pip' error occurs when executing pip command
The cause of the problem: the pip module is not installed in the system
Solution:

python -m ensurepip
python -m pip install --upgrade pip

Recommended Posts

Python3 configuration and entry.md
Python and Go
Python introspection and reflection
OpenMPI-Ubuntu installation and configuration
Python function-Bunch configuration loading
[python] python2 and python3 under ubuntu
Python deconstruction and packaging
Python automated operation and maintenance 2
Python introduction and environment installation
Python know crawler and anti crawler
centos7 install python3 and ipython
Centos mysql installation and configuration
Centos7 installation and configuration prometheus
ubuntu18.04 compile and install python3.8
CentOS 7 installation and configuration PPTP
CentOS installation and configuration cmake
Centos7.5 installation and configuration MongoDB4.0.4
CentOS 7 installation and configuration PPTP
CentOS7 install python3 and pip3
Python automated operation and maintenance 1
Python data structure and algorithm
Python multi-process and multi-thread basics
CentOS 6.9 compile and install python
CentOS 6 compile and install python 3
Ubuntu16.04 install SVN and configuration
Generators and iterators in Python
Ubuntu PostgreSQL installation and configuration
Centos7 installation and configuration of Jenkins
Python file read and write operations
Python and js interactive call method
CentOS 8 install Git and basic configuration
Ubuntu environment variables and ADB configuration
Python judges positive and negative numbers
python ftp upload files and folders
Python crawler | Cognitive crawler request and response
How to write python configuration file
FM algorithm analysis and Python implementation
Centos7 hadoop cluster installation and configuration
Common errors and solutions in python
Python implements string and number splicing
Ubuntu16.04 configuration OpenCV3.4.2 and basic use
CentOS quickly install Python3 and pip3
Mongodb and python interaction of python crawler
Install Python3 and ansible under CentOS8
Python processing PDF and CDF examples
CentOS 7 Tomcat service installation and configuration
Centos 7 RAID 5 detailed explanation and configuration
Played with stocks and learned Python
Configure python3 environment on centos7 and
Ubuntu 19.1 installation and configuration Chinese environment
Python reads and writes json files
Configuration and beautification after Ubuntu installation (1)
Python implements username and password verification
Nginx installation and configuration load (ubuntu12.04)
Install Python3 and Py under CentOS7
Ubuntu configuration source and installation software
Centos7 mysql database installation and configuration
Python basic syntax and number types
Python learning os module and usage
CentOS 7 system installation and configuration graphic tutorial
Getting Started with Python-4: Classes and Objects