创建环境
打开https://dsw-dev.data.aliyun.com/,进入DSW环境
DSW环境默认的python环境配置python版本为3.6,但是在实际开发过程中,安装软件包依赖更高的python版本,这样一些软件包不能使用合适的版本,那有什么方法可以使用吗,这里就是用conda再创建一个环境,安装更新的版本软件。
File->New->Terminal打开终端,
使用conda create命令创建名为py39的环境,使用的python版本为3.9
sh-4.2$ which conda
/opt/conda/bin/conda
sh-4.2$ conda create --name py39 python=3.9 # 创建python3.9的虚拟环境
Collecting package metadata (current_repodata.json): done
Solving environment: done
==> WARNING: A newer version of conda exists. <==
current version: 4.9.2
latest version: 4.13.0
Please update conda by running
$ conda update -n base conda
## Package Plan ##
environment location: /home/admin/.conda/envs/py39
added / updated specs:
- python=3.9
The following NEW packages will be INSTALLED:
_libgcc_mutex anaconda/pkgs/main/linux-64::_libgcc_mutex-0.1-main
_openmp_mutex anaconda/pkgs/main/linux-64::_openmp_mutex-5.1-1_gnu
ca-certificates anaconda/pkgs/main/linux-64::ca-certificates-2022.4.26-h06a4308_0
certifi anaconda/pkgs/main/linux-64::certifi-2022.6.15-py39h06a4308_0
ld_impl_linux-64 anaconda/pkgs/main/linux-64::ld_impl_linux-64-2.38-h1181459_1
libffi anaconda/pkgs/main/linux-64::libffi-3.3-he6710b0_2
libgcc-ng anaconda/pkgs/main/linux-64::libgcc-ng-11.2.0-h1234567_1
......
Proceed ([y]/n)? y
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
# $ conda activate py39
#
# To deactivate an active environment, use
#
# $ conda deactivate
使用
然后切换shell为bash,再运行conda activate py39,便切换到新创建的环境,查看安装的python版本为python 3.9.12
sh-4.2$ bash
(base) [admin@d20220630143618d35b74e10cea001390033-6975cd4898-9hqn9 jupyter]$ conda activate py39
(py39) [admin@d20220630143618d35b74e10cea001390033-6975cd4898-9hqn9 jupyter]$ python --version
Python 3.9.12
(py39) [admin@d20220630143618d35b74e10cea001390033-6975cd4898-9hqn9 jupyter]$
安装tensorflow,可以看到安装的版本为2.9.1,是比较新的版本
(py39) [admin@d20220630143618d35b74e10cea001390033-6975cd4898-9hqn9 jupyter]$ pip install tensorflow
Looking in indexes: https://mirrors.aliyun.com/pypi/simple
Collecting tensorflow
Downloading https://mirrors.aliyun.com/pypi/packages/fd/0a/4772fb94cf9b4ad7553c253193afc2e7ea5403f7390976885e5066e3d518/tensorflow-2.9.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (511.7 MB)
|▎ | 4.9 MB 449 kB/s eta 0:18:49
然后可以继续安装其他需要的依赖包
安装到ipykernel
集成到ipykernel环境
(py39) [admin@d20220630143618d35b74e10cea001390033-6975cd4898-9hqn9 jupyter]$ pip install ipykernel
(py39) [admin@d20220630143618d35b74e10cea001390033-6975cd4898-9hqn9 jupyter]$ python -m ipykernel install --user
Installed kernelspec python3 in /home/admin/.local/share/jupyter/kernels/python3
新建notebook,查看python版本为3.9,版本已切换