Python虚拟环境指南2024版_yydsd

本文介绍了如何通过miniconda安装和管理conda环境,以及如何在该环境中使用pip安装JupyterLab和Python库,如numpy、matplotlib等。还强调了在Python学习中系统化学习的重要性,并提供了丰富的学习资源和社区支持。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

大家也可以直接体验jupyter.org/try-jupyter…

环境安装

可以使用下面命令安装miniconda:

curl https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh | sh
复制代码

安装完成miniconda后可以这样创建和使用虚拟环境:

# Best practice, use an environment rather than install in the base env
conda create -n my-env
conda activate my-env
# If you want to install from conda-forge
conda config --env --add channels conda-forge
# The actual install command
conda install numpy
复制代码

这使用起来和Python的虚拟环境类似:

python3 -m venv .venv
source .venv/bin/activate
pip install numpy
复制代码

当然,你可以在conda环境中直接使用pip:

(my-env) [game404@y ~]$ pip list
Package    Version
---------- -------
numpy      1.24.1
pip        22.3.1
setuptools 65.6.3
wheel      0.38.4
复制代码

我们可以使用下面两个命令之一安装jupyterlab:

conda install jupyterlab
或者
pip install jupyterlab
复制代码
  • conda命令是从anaconda源安装;pip是用PyPi源安装,两个命令异曲同工,就看谁网速快

启动jupyter-lab

安装完jupyter-lab后,可以使用下面命令打开它:

(my-env) [game404@y ~]$jupyter-lab
[I 2023-01-08 21:26:50.250 ServerApp] jupyter_server_terminals | extension was successfully linked.
[I 2023-01-08 21:26:50.257 ServerApp] jupyterlab | extension was successfully linked.
[I 2023-01-08 21:26:50.262 ServerApp] nbclassic | extension was successfully linked.
...
[I 2023-01-08 21:26:50.842 ServerApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[W 2023-01-08 21:26:50.847 ServerApp] No web browser found: could not locate runnable browser.
[C 2023-01-08 21:26:50.848 ServerApp]

    To access the server, open this file in a browser:
        file:///home/yuanzuxiang/.local/share/jupyter/runtime/jpserver-3540-open.html
    Or copy and paste one of these URLs:
        http://localhost:8889/lab?token=f5028b1978baa74512cec56cff7c4f9e2dbbc4592cdf5b69
     or http://127.0.0.1:8889/lab?token=f5028b1978baa74512cec56cff7c4f9e2dbbc4592cdf5b69
复制代码
  • 注意这里的token,是权限访问的token, 初次访问首页需要使用

然后我们通过浏览器访问jupyter-lab,创建Notebook,直接测试python环境:

  • 红色的Notebook Icon和引导界面一致
  • 使用顶部工具栏【->】执行代码
  • notebook主要是可以按照cell执行代码

安装常用库

安装好Python环境和Jupyter-lab工具后,接下来我们开始安装常用库,主要涉及下面7个库:

  • numpy The fundamental package for scientific computing with Python
  • pandas is a fast, powerful, flexible and easy to use open source data analysis and manipulation tool, built on top of the Python programming language.
  • matplotlib Matplotlib is a comprehensive library for creating static, animated, and interactive visualizations in Python. Matplotlib makes easy things easy and hard things possible.
  • seaborn is a Python data visualization library based on matplotlib.
  • scipy Fundamental algorithms for scientific computing in Python
  • statsmodels statistical models, hypothesis tests, and data exploration

在这里插入图片描述

感谢每一个认真阅读我文章的人,看着粉丝一路的上涨和关注,礼尚往来总是要有的:

① 2000多本Python电子书(主流和经典的书籍应该都有了)

② Python标准库资料(最全中文版)

③ 项目源码(四五十个有趣且经典的练手项目及源码)

④ Python基础入门、爬虫、web开发、大数据分析方面的视频(适合小白学习)

⑤ Python学习路线图(告别不入流的学习)

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里无偿获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值