惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
U
Unit 42
GbyAI
GbyAI
M
MIT News - Artificial intelligence
美团技术团队
罗磊的独立博客
雷峰网
雷峰网
量子位
博客园 - 【当耐特】
Last Week in AI
Last Week in AI
D
Docker
小众软件
小众软件
S
SegmentFault 最新的问题
Blog — PlanetScale
Blog — PlanetScale
阮一峰的网络日志
阮一峰的网络日志
宝玉的分享
宝玉的分享
T
Tailwind CSS Blog
WordPress大学
WordPress大学
V
V2EX
博客园_首页
腾讯CDC
The Cloudflare Blog
A
About on SuperTechFans
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC

jdhao's digital space

Conversion between base64 and OpenCV or PIL Image 腾讯云对象存储博客图床开启 CDN 加速(不需要购买额外域名) Search and Replace in Multiple Files in Vim/Neovim Change Table Column Width in LaTeX Image or Table Side by Side in LaTeX LaTeX 并排显示图像或表格 Firenvim: Neovim inside Your Browser Content inside HTML tags missing in Latest Hugo? Creating Markdown Front Matter with Ultisnips Labelme JSON 标注格式转 voc XML 格式 Nifty Nvim Techniques That Make My Life Easier -- Series 6 macOS 下如何为视频制作字幕 Running Command Asynchronously inside Neovim Resolving Merge Conflict after Git Stash Pop Pylint: command not found? A Hands-on Experience with Neovim's Built-in LSP Support How to Convert PDF to Images with Imagemagick 互联网上常用缩略语集锦 File Backup in Neovim Converting PDF Pages to Images with Poppler Nifty Nvim Techniques That Make My Life Easier -- Series 5 Neovim Configuration for System-wide Use How to sort a list of tuple or list in Python -- lambda or itemgetter? Building A Vim Statusline from Scratch 人类第一颗原子弹爆炸始末 Distributed Training in PyTorch with Horovod Learning Expect Programming Essential Knowledge about SSH Nifty LaTeX Techniques -- Series 1 更改 Adsense 邮寄地址,重新寄送 PIN
Using Virutal Environment in Python with venv
2023-10-11 · via jdhao's digital space

Using a virtual environment for Project dev in Python is a good practice. venv is module that is available since Python 3.3. It can help us to manage the virtual environment in a simple way.

Manage virtual env#

Create a virtual env#

Normally, we create a virtual environment under the project root directory:

python -m venv paht/to/project-root/venv

The name we give to this virtual env is venv. Under the directory venv, there are different files and folders. Under my macOS system, it has the following files:

bin/        include/    lib/        pyvenv.cfg

Activate and de-activate#

To activate the virtual environment, run this command:

Then your shell prompt changes and tells you are now in the virtual environment. When the environment has been activated, the VIRTUAL_ENV env variable is set to the path of the environment.

To deactivate the virtual environment, just run deactivate.

ref:

Make jupyter work with virtual env#

First, we need to install the ipykernel package inside the virtual env:

Then we can generate a kernelspec for jupyter:

python -m ipykernel install --user --name <spec-name>
# output: Installed kernelspec venv in /Users/<your-user-name>/Library/Jupyter/kernels/<spec-name>

Now we can open the notebook:

jupyter notebook <your-notebook-name>.ipynb

In the opened browser tab for jupyter, we can click the Kernel menu and click change kernel to switch the kernel.

Kernelspec management#

To list your kernelspecs:

To remove the virtual env spec:

jupyter kernelspec remove <spec-name>

ref: