linux wrapper 安装服务,在Linux系统上安装virtualenvwrapper虚拟环境,Virtualenvwrapper

操作系统版本:CentOS 3.6.8

Python版本:python 3.6.8 和 python 3.7.5 共存,默认python版本是python 3.6.8

Linux环境如何配置多版本python共存环境? 请您看一下

这篇博文

1.安装虚拟环境

使用 df  -lh 指令查看系统挂载节点空间大小,本实例中,将虚拟环境配置在/home中。安装指令如下:

[root@localhost ~]# pip install virtualenv

[root@localhost ~]# pip install virtualenvwrapper

[root@localhost ~]# cd /home && mkdir .virtualenvs

2.配置环境变量

# 确认文件位置

[root@localhost home]# whereis virtualenvwrapper.sh

virtualenvwrapper: /usr/local/bin/virtualenvwrapper.sh

# 编辑配置文件

[root@localhost home]# vim ~/.bashrc

# 此处注释为了解释代码功能,配置时无需键入。

# 虚拟文件存放位置

export WORKON_HOME=/home/.virtualenvs

# 虚拟工具位置

source /usr/local/bin/virtualenvwrapper.sh

# 虚拟环境的解释器位置(此前配置的软连接)

VIRTUALENVWRAPPER_PYTHON=/usr/bin/python

# 环境变量编辑完成,保存并退出vim编辑器。

# 此时,刷新配置,出现下面的结果表示配置成功

[root@localhost aoto_dialogue]# source ~/.bashrc

virtualenvwrapper.user_scripts creating /home/aoto_dialogue/.virtualenvs/premkproject

virtualenvwrapper.user_scripts creating /home/aoto_dialogue/.virtualenvs/postmkproject

virtualenvwrapper.user_scripts creating /home/aoto_dialogue/.virtualenvs/initialize

。。。

3.测试虚拟环境

为了确认虚拟环境安装是否满足要求,创建一个虚拟环境进行测试,主要测试虚拟环境的安装与虚拟环境和外部环境解释器是否已经进行区分;

[root@localhost aoto_dialogue]# mkvirtualenv test # 新建虚拟环境test

# 执行上述创建操作后,会显示十几行日志,随后便进入虚拟环境中(命令行前方有虚拟环境名称)

(test) [root@localhost aoto_dialogue]# python --version

Python 3.6.8

(test) [root@localhost aoto_dialogue]# python # 进入python

Python 3.6.8 (default, Nov 30 2020, 15:43:08)

[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux

Type "help", "copyright", "credits" or "license" for more information.

>>> import sys

>>> sys.executable # 查看当前解释器的位置是否是虚拟环境文件的位置,如下为正确位置

'/home/aoto_dialogue/.virtualenvs/test/bin/python'

>>> quit()

(test) [root@localhost aoto_dialogue]# deactivate # 退出虚拟环境

[root@localhost aoto_dialogue]# rmvirtualenv test # 删除测试环境

Removing test...

虚拟环境安装完成

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Virtualenvwrapper is a tool that simplifies the management of Python virtual environments in Linux. It provides a set of commands to create, activate, and delete virtual environments, making it easier to work with different Python projects with their own dependencies. To use Virtualenvwrapper, you need to have Python and Virtualenv installed on your system. Here are the steps to set up Virtualenvwrapper on Linux: 1. Install Virtualenv: ``` $ pip install virtualenv ``` 2. Install Virtualenvwrapper: ``` $ pip install virtualenvwrapper ``` 3. Add the following lines to your shell startup file (e.g., `~/.bashrc` or `~/.bash_profile`): ``` export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3 # Path to your Python interpreter export WORKON_HOME=~/.virtualenvs # Directory to store virtual environments source /usr/local/bin/virtualenvwrapper.sh # Path to virtualenvwrapper.sh ``` 4. Reload the shell startup file: ``` $ source ~/.bashrc ``` 5. Create a virtual environment: ``` $ mkvirtualenv myenv ``` 6. Activate the virtual environment: ``` $ workon myenv ``` Now you can install Python packages within the virtual environment without affecting your system-wide Python installation. You can also switch between different virtual environments using the `workon` command. Remember, Virtualenvwrapper is just a wrapper around Virtualenv, so it uses the same underlying mechanisms for creating and managing virtual environments. It provides additional convenience commands and organizes virtual environments in a more structured way.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值