- 请尽可能不用Ubuntu24
- 请直接跳7.查看解决方案
Action Log
- 在Ubuntu 24.04中更换为清华源的步骤
- 【Bug】Python 3.12 on Ubuntu 24.04 is Externally Managed - PIP is broken
相关解决方案
从 Ubuntu 24.04 开始,有两个选项:
1. install python pacakges/modules system wide via "sudo apt install python3-<Packagename>" ... which is not the case for pytube because: not avaiable as ubuntu package
通过“sudo apt install python3-”在系统范围内安装 python 包/模块 “... pytube 的情况并非如此,因为:无法作为 ubuntu 包使用
2. create a python venv (virtual env), and from there install via pip.
创建一个 python venv(虚拟环境),然后从那里通过 pip 安装。
- 修复pip
- 安装系统的py3.12的pip
sudo add-apt-repository universe
sudo apt update && sudo apt upgrade
sudo apt install python3-pip
- 在 Ubuntu 24 中,软件包需要彼此隔离。因此 pipx 将每个软件包安装在其自己的隔离环境中。
而在 Ubuntu 22 中,您可以直接使用 pip install 因为没有这个要求。
sudo apt install pipx
pipx install numpy
pipx install ....
- 安装虚拟环境
apt install pipenv
- 配置pipenv
vim ~/.profile
- 打开profile文件后(i),添加下面命令进行路径配置接即可成功完成pipenvshell的安装预配置:
export PATH=$PATH:/home/<自己的用户名>/.local/bin
【esc】–【:】–【wq】–【enter】
- 更新
source ~/.profile
- [项目dir]进入项目文件夹,创建该项目的虚拟环境
cd /project*
pipenv shell
pipenv shell 进入虚拟环境
exit 退出虚拟环境
pipenv --rm 删除整个环境,不会删除pipfile
然后得到输出含:
...
Successfully created virtual environment!
...
(project*)root@设备名称:/文件夹绝对路径#
- [项目dir]查看现有的安装包
pip list
- [项目dir]安装项目所需的环境库包
pip install -r requirements.txt -v/
- [系统dir]发现我的库包需要python3.9(系统python3.12)
如何在Ubuntu24.04系统上安装Python 3.10:PPA和源码编译两种方法
查看Python版本:ls /usr/bin/python*
- 安装python3.9及其dev :
重点是:python3.9-venv python3.9-dev
sudo apt install python3.9 python3.9-venv python3.9-dev
Ubuntu修改系统级Python版本:
- 基于update-alternatives:
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.9 2
- 基于软链接:
sudo ln -s /usr/bin/python3.9 /usr/bin/python
- 实现项目的环境(python3.9及其pip)
实现路径:系统安装python3.9及其pip——虚拟环境建立导入——install应用包
a. [系统dir]将pip版本更改为符合当前的Python版本
apt安装【失败】
sudo apt remove python3-pip
sudo apt install python3-pip
get-pip安装【成功】
sudo curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python3.9 get-pip.py
b. [项目dir]项目虚拟环境里配置python3.9
[项目dir]项目虚拟pipenv环境里配置python3.9
sudo pipenv --python 3.9
pipenv shell
pipenv install streamlit numpy
...
[项目dir]项目python -m venv myenv里配置python3.9【成功】
sudo python3.9 -m venv myenv
source myenv/bin/activate
sudo chown -R $USER:$USER /..项目文件夹绝对路径../apps
pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install numpy streamlit numpy-financial pandas json5 datetime plotly -i https://pypi.tuna.tsinghua.edu.cn/simple
...
最终项目文件夹目录
—projects
——files
——myenv
——get-pip.py
- [项目dir]项目虚拟环境包-m venv myenv里配置python3.9
实现路径:系统安装python3.9——虚拟环境建立导入并对应安装pip——install应用包
sudo python3.9 -m venv myenv --without-pip
sudo source myenv/bin/activate
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python3.9 get-pip.py
pip install numpy streamlit numpy-financial pandas json5 datetime plotly -i https://pypi.tuna.tsinghua.edu.cn/simple
...
- 【选】删除/重装(前)虚拟环境
sudo rm -rf myenv