Python environment and installation

1. Distribution of Python

Compared to C++, which can run only with an executable file, Python source code should run with the interpreter. So you should know how to install an interpreter on your computer.

Typically, we won't install the python interpreter directly. We install a distribution of Python, which contains one or more than one interpreters , some useful standard librarys and other components. I will show how to install python in linux machine. Before that, I'd like to mention the important virtual environment for python.

2. I want to specify the virtual environment of Python.

When you install a distribution of Python, you may want to run a source code immediately. However, we usually don't do so. You will use a lot of librarys in your source code so that you should install a all of them so that your program will run normally. However, installing them globally is not recommended.

We usually create a virtual environment , and then install some librarys in the environment. The essense of a python environment is a folder which contains an independent interpreter and some librarys you installed. You can create more than 1 environments and when you want to run your code, choose a moderate one and activate it, then use the environment to run your code.

For instance:

bash 复制代码
# in windows system


python -m venv environment1         # create an environment

python -m venv environment2         # create another environment

# ===============================================================================
# you will see 2 folders in current folder, environment1/ and environment2/

environment1\Scripts\activate       #activate the environment
  
pip install numpy                   # install a library named numpy, the library is installed in environment1

deactivate                          # exit the environment

Now the library numpy is in environment1 , not in environment2.

Now you have a text file named my_python.py of source code using the library numpy

bash 复制代码
environment1\Scripts\activate

python my_python.py  # ok

=================================================================
environment2\Scripts\activate

python my_python.py  # error, environment2 hasn't numpy

The benefit of using virtual environment is obviously. Different projects use different environment, for example, Web projects utilize an environment with librarys like requests, flank and so on. It will make your projects more adaptive.

3. Installation of Python (in Linux System)

Steps are as follows:

1. Choose:

  • choose a python distribution. You can choose official distribution or Anaconda. Anaconda is a python distribution specifically designed for AI and data process, containing more than one python interpreters of different versions, and a lot of librarys for scientific computint.

2. Install:

After installing the distribution, you can create an environment and begin coding!

  1. activate an envitonment
bash 复制代码
python -m venv my_environment

my_environment\Scripts\activate
  1. write the code into a text file with suffix .py , for example, test.py

  2. run

bash 复制代码
#supposed that test.py is in home/python/test.py

cd home/python

python3 test.py

In this part, you know what is python envitonment and how to use it.

4. IDE installation

Just using a text deitor is boring. We need some powerful tool to help us write code and run the program. You surely don't want to write code in a plain text editor and run with python3 test.py

An Integrated development environment(IDE) is what you need, and I recomment **Pycharm,**a powerful IDE. How to install Pycharm is simple and ignored here. What I want to emphisize is how to use environment in Pycharm.

.

  1. Install Pycharm

  2. Tell what environment you want to use, click the setting button and find Interpreter

  1. Click Add Interpreter , and enter the file system to fine your interpreter . Remember that every virtual environment has an independent Interpreter, find it and add it to pycharm.

Last but not least, If you encounter any questions during installation, feel free to ask AI.

相关推荐
nagualky123几秒前
GPT-4 系列退役在即:一套可回滚的模型迁移验收法
java·开发语言·ai·架构
小小张说故事2 分钟前
Python 里 a is b 有时 True 有时 False?小整数缓存和常量折叠的底层真相
python
Ai-_Man3 分钟前
DeepSeek生成的内容能否下载吗?
开发语言·javascript·人工智能·小程序·ecmascript
Evelvnk5 分钟前
计算机学习资料
开发语言·人工智能·计算机·php
我的xiaodoujiao5 分钟前
Django 基础知识详细图文教程 16-Django 内置Admin认证系统
后端·python·django
ZGonce8197 分钟前
vLLM 使用实战:在 8GB 显卡上完成模型部署、并发压测与显存调优
python
geovindu15 分钟前
rust: Chain of Responsibility Pattern
开发语言·后端·设计模式·rust·责任链模式·行为模式
阿里嘎多学长18 分钟前
2026-10-14 GitHub 热点项目精选
开发语言·程序员·github·代码托管
迪康coolmu19 分钟前
迪康Defender网络准入控制系统落地实战:部署、配置与问题排查记录
运维·开发语言·网络·经验分享·php
兰亭妙微UI设计公司19 分钟前
兰亭妙微分享:高手设计登录页的12种切入点
开发语言·前端·javascript