today ,Python The application scenarios of are more and more widely used , Such as operation and maintenance 、AI Learning, etc. . It can be considered as a necessary skill to master . I will open a new series of courses , Really, really 0 Become familiar with the language . The whole series will cover 3 Big content :1、Python Basics ;2、 use ptyhon Realize another series of the author (grpc Distributed framework ) Service procedures in ;3、AI The content of machine learning .
The author's development environment :macos、pycharm、anaconda, python edition :python3.9
Several installation methods will be introduced here , It is strongly recommended to use anaconda Management is then integrated into pycharm in .
Use brew install , The installed directory is in :/usr/local/Cellar Directory , perform search command :
Then select a version , I installed 3.8 and 3.9 Two versions , Proposed installation 3.9 edition .
# install python
brew search python
brew install python
Set the environment variable
PATH = "/Library/Frameworks/Python.framework/Versions/3.9/bin:${PATH}"
export PATH
alias python = "/Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9"
source ~ /. bash_profile
Install common libraries ( similar Java The third party of jar package ), such as numpy package , The following commands are available
# adopt pip install python library
pip3 install -- user url The private package is installed to site - packages The following is only for this project
pip3 install pkg Global installation
Last , Enter... On the command line ptyhon or python3, You can see the version information and enter python Environmental Science , as follows :
This is a Python Environmental management software , It comes with common third-party libraries and some necessary software ( be chiefly used in AI Programming related ). This need not say too much , Find the corresponding version on the Internet , install . Then click on the left 【environments】 Again 【create】 New or 【clone】 An existing environment , As shown in the figure below , At most
Re selection 【home】 View available software , Installed can be run directly or selected 【install】 Installation ( Sometimes the installation is slow , Suggest more times )
Premise : Installed pycharm Software is used in parallel anaconda Set up a new environment , The author's environment is called 【liudong】
have small change for pycharm, Select File -> New project settings , Here's the picture , stay python The interpreter selects the environment created above , You can also create a new environment through the gear on the right .
We can follow up on pycharm It can also be in anaconda In the management jar, The effect is the same
Interpreter description :
- Virtualenv Environmental Science : Equivalent to a private environment , A folder will be created in the project , There are libraries related to this project ;
- Conda Environmental Science : It is equivalent to a public environment , See above ;
- System interpreter : In some operating systems, there will be one by default ptyhon Environmental Science , Not recommended ;
- Pipenv Environmental Science : use pip To manage library packages, etc , see 1.1 Install library commands described in section ;
The project created by the author is as follows :
We are app/base Create a new one in the directory helloworld.py file , Create the first one py Program .
print( "hello world")
Right click to run , The console will output the following :
/ Users / liudong /. conda / envs / liudong / bin / python / Users / liudong / personCode / python / pythonTest / app / base / helloworld. py
hello world
Process ended , Exit code 0
stay python There are two types of objects with fixed length and variable length , Among them, variable length objects are divided into variable and immutable objects , stay python All built-in objects in are statically initialized , Other objects are initialized on the heap . Once an object is created, its memory size is immutable , So a mutable object does not maintain a value but an address pointer .
English document Chinese document