程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python from door to master (I): basic -01- development environment configuration

編輯:Python

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

One 、 install

Several installation methods will be introduced here , It is strongly recommended to use anaconda Management is then integrated into pycharm in .

1.1、 Command line installation

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
  • 1.
  • 2.
  • 3.

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
  • 1.
  • 2.
  • 3.
  • 4.

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
  • 1.
  • 2.
  • 3.

Last , Enter... On the command line ptyhon or python3, You can see the version information and enter python Environmental Science , as follows :

1.2、 adopt anaconda install ( recommend )

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 )

Two 、 And IDEA Integrate

Premise : Installed pycharm Software is used in parallel anaconda Set up a new environment , The author's environment is called 【liudong】

2.1、 Set the default interpreter for new projects

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


3、 ... and 、 first py Program

3.1、 newly build python project

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 ;

3.1、 first python Program

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")

  • 1.

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
  • 1.
  • 2.
  • 3.
  • 4.

Four 、 Standard library help manual

4.1、 Overall framework

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 .

  • middle : Express python Data flow process : Lexical analysis , Analyze the source code to generate multiple token--> Syntax analysis , establish AST--> Generate instruction set , establish python Bytecode -->VM Environmental Science , Execution bytecode
  • On the right side : Built in object system 、 Memory allocation 、 Runtime status monitor ( Responsible for monitoring different runtime states of bytecode )
  • left :python A large number of built-in modules 、 Libraries and user-defined modules

 ​ English document ​​​  ​ ​ Chinese document ​​



  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved