linux环境
安装wsl:vscode + wsl1 搭建远程开发环境
安装python
- 更新apt
sudo apt update
- 安装python3.8,pip, ipython
sudo apt install python3 python3-pip ipython3
- 设置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