[ TOC]
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'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 "Edit with IDLE" 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 "Open Method" of "Properties", 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 "this computer"->"Advanced System Settings"->"Environmental Variables(N)...", 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'clock, select execute with the right mouse button.
In the registry: HKEY_CLASSES_ROOT\Python.File\shell\New item in "via Python2.7Run", then create a new item "command", set the default value to:"C:\Python27\python.exe""%1"%*Can
WeiyiGeek. Right-click to open
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
# 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