搭建项目环境
Create a Project Driectory
mkdir my_python_project
cd my_python_project
Create a Virtual Environment
# For Python 3
python3 -m venv venv
Activate the Virtual Environment
# On Windows
venv\Scripts\activate
# On Unix or MacOS
source venv/bin/activate
# Exist venv env
deactivate
Create requirements.txt
or Pipfile
requirements.txt
: Traditional method where you list dependencies manually.
touch requirements.txt
Pipfile
: If you use pipenv, which is a more modern alternative topip
.
pip install pipenv
pipenv --python 3.x # x is your minor version
Install Dependencies
As your project grows, you'll add dependencies here, and install them:
# Using pip
pip install -r requirements.txt
# Using pipenv
pipenv install
Create the Main Project File
Version Control
git init
If you're using Git, remember to create a .gitignore
file to avoid committing unnecessary files:
touch .gitignore
Include venv/
and other files/directories you want to exclude from version control.
Other Considerations
- README: Create a
README.md
to document the purpose, installation, and usage of your project. - Unit Testing: Consider setting up a testing framework like
unittest
orpytest
. - Linter/Formatter: Tools like
flake8
for linting andblack
for formatting help in maintaining code quality. - Continuous Integration/Continuous Deployment (CI/CD): For more advanced projects, you might want to set up CI/CD pipelines using tools like Jenkins, GitLab CI, or GitHub Actions.
Vscode
plugin
- Python
- Black Formatter
- Prettier - Code formatter