python 开发环境配置

linux环境

安装wsl:vscode + wsl1 搭建远程开发环境

安装python

  1. 更新apt
sudo apt update
  1. 安装python3.8,pip, ipython
sudo apt install python3 python3-pip ipython3
  1. 设置pip 源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

安装poetry

pip3 install poetry

通过以下命令设置首选镜像:

poetry source add --priority=primary mirrors https://pypi.tuna.tsinghua.edu.cn/simple/

通过以下命令设置补充镜像:

poetry source add --priority=supplemental mirrors https://pypi.tuna.tsinghua.edu.cn/simple/

pip 警告处理:WARNING: The script doesitcache is installed in ‘/home/leeyorke/.local/bin’ which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
对于 vim 或 vi,你可以使用:
vi ~/.bashrc
Copy
在文件的末尾添加以下行:
export PATH=“$PATH:/home/leeyorke/.local/bin”
保存并退出编辑器。
使更改生效。在终端中运行以下命令:
source ~/.bashrc

测试是否安装成功

poetry -V

poetry 命令

Poetry (version 1.8.0)

Usage:
  command [options] [arguments]

Options:
  -h, --help                 Display help for the given command. When no command is given display help for the list command.
  -q, --quiet                Do not output any message.
  -V, --version              Display this application version.
      --ansi                 Force ANSI output.
      --no-ansi              Disable ANSI output.
  -n, --no-interaction       Do not ask any interactive question.
      --no-plugins           Disables plugins.
      --no-cache             Disables Poetry source caches.
  -C, --directory=DIRECTORY  The working directory for the Poetry command (defaults to the current working directory).
  -v|vv|vvv, --verbose       Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug.

Available commands:
  about              Shows information about Poetry.
  add                Adds a new dependency to pyproject.toml.
  build              Builds a package, as a tarball and a wheel by default.
  check              Validates the content of the pyproject.toml file and its consistency with the poetry.lock file.
  config             Manages configuration settings.
  export             Exports the lock file to alternative formats.
  help               Displays help for a command.
  init               Creates a basic pyproject.toml file in the current directory.
  install            Installs the project dependencies. 
  list               Lists commands.
  lock               Locks the project dependencies.
  new                Creates a new Python project at <path>. # 创建一个新的python项目
  publish            Publishes a package to a remote repository.
  remove             Removes a package from the project dependencies.
  run                Runs a command in the appropriate environment.
  search             Searches for packages on remote repositories.
  shell              Spawns a shell within the virtual environment. # 进入虚拟环境
  show               Shows information about packages.
  update             Update the dependencies as according to the pyproject.toml file.
  version            Shows the version of the project or bumps it when a valid bump rule is provided.

 cache
  cache clear        Clears a Poetry cache by name.
  cache list         List Poetry's caches.

 debug
  debug info         Shows debug information.
  debug resolve      Debugs dependency resolution.

 env
  env info           Displays information about the current environment.
  env list           Lists all virtualenvs associated with the current project.
  env remove         Remove virtual environments associated with the project.
  env use            Activates or creates a new virtualenv for the current project.

 self
  self add           Add additional packages to Poetry's runtime environment.
  self install       Install locked packages (incl. addons) required by this Poetry installation.
  self lock          Lock the Poetry installation's system requirements.
  self remove        Remove additional packages from Poetry's runtime environment.
  self show          Show packages from Poetry's runtime environment.
  self show plugins  Shows information about the currently installed plugins.
  self update        Updates Poetry to the latest version.

 source
  source add         Add source configuration for project.
  source remove      Remove source configured for the project.
  source show        Show information about sources configured for the project.

注意:

poetry install 用于安装项目中已定义的依赖项,确保所有依赖项都被安装。
poetry add 用于向项目中添加新的依赖项,并更新 pyproject.toml 和 poetry.lock 文件。

开始开发

输入poetry new my_project新建一个名为 my_project 的项目。

.
├── README.md
├── my_project
│   └── __init__.py
├── pyproject.toml
└── tests
    └── __init__.py
  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Python开发环境配置有多种方式,其中一种常用的方式是使用Anaconda。Anaconda是一个开源的Python发行版,它包含了Python解释器以及许多常用的第三方库和工具。以下是配置Python开发环境的步骤: 1. 下载安装Anaconda:首先,你需要从Anaconda官网下载适合你操作系统的Anaconda安装包,并按照官方文档的指引进行安装。 2. 创建虚拟环境:使用conda命令创建一个新的虚拟环境。例如,可以运行以下命令创建一个名为demo的虚拟环境,并指定Python版本为3.8: ``` conda create -n demo python=3.8 ``` 3. 激活虚拟环境:创建虚拟环境后,需要激活虚拟环境才能使用其中安装的Python解释器和库。在Windows系统下,可以运行以下命令来激活demo环境: ``` conda activate demo ``` 在Mac和Linux系统下,可以运行以下命令来激活demo环境: ``` source activate demo ``` 4. 安装依赖包:在激活虚拟环境后,可以使用conda或pip命令安装所需的第三方库。例如,可以使用conda命令安装numpy包: ``` conda install numpy ``` 或者使用pip命令安装numpy包: ``` pip install numpy ``` 如果需要安装特定版本的库,可以使用相应的命令指定版本号。 5. 验证安装:安装完成后,可以使用conda list或pip list命令查看已安装的包列表: ``` conda list ``` 或 ``` pip list ``` 这样可以确保所需的库已经成功安装。 以上是使用Anaconda配置Python开发环境的基本步骤。通过创建虚拟环境和安装所需的库,你可以在不同的项目中使用不同的Python版本和库集合,以满足各种开发需求。当然,除了Anaconda,还有其他方式可以配置Python开发环境,可以根据自己的需求选择适合的方式进行配置。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值