设置python 虚拟环境 virtualenv django 虚拟环境
https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/development_environment
Ubuntu virtual environment setup
After installing Python and pip you can install virtualenvwrapper (which includes virtualenv). The official installation guide can be found here, or follow the instructions below.
Install the tool using pip3:
sudo pip3 install virtualenvwrapper
Then add the following lines to the end of your shell startup file (this is a hidden file name .bashrc in your home directory). These set the location where the virtual environments should live, the location of your development project directories, and the location of the script installed with this package:
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export VIRTUALENVWRAPPER_VIRTUALENV_ARGS=' -p /usr/bin/python3 '
export PROJECT_HOME=$HOME/Devel
source /usr/local/bin/virtualenvwrapper.sh
Note: The VIRTUALENVWRAPPER_PYTHON and VIRTUALENVWRAPPER_VIRTUALENV_ARGS variables point to the normal installation location for Python3, and source /usr/local/bin/virtualenvwrapper.sh points to the normal location of the virtualenvwrapper.sh script. If the virtualenv doesn't work when you test it, one thing to check is that Python and the script are in the expected location (and then change the startup file appropriately).
You can find the correct locations for your system using the commands which virtualenvwrapper.sh and which python3.
Then reload the startup file by running the following command in the terminal:
source ~/.bashrc
At this point you should see a bunch of scripts being run as shown below:
virtualenvwrapper.user_scripts creating /home/ubuntu/.virtualenvs/premkproject
virtualenvwrapper.user_scripts creating /home/ubuntu/.virtualenvs/postmkproject
...
virtualenvwrapper.user_scripts creating /home/ubuntu/.virtualenvs/preactivate
virtualenvwrapper.user_scripts creating /home/ubuntu/.virtualenvs/postactivate
virtualenvwrapper.user_scripts creating /home/ubuntu/.virtualenvs/get_env_details
Now you can create a new virtual environment with the mkvirtualenv command.
macOS virtual environment setup
Setting up virtualenvwrapper on macOS is almost exactly the same as on Ubuntu (again, you can follow the instructions from either the official installation guide or below.
Install virtualenvwrapper (and bundling virtualenv) using pip as shown.
sudo pip3 install virtualenvwrapper
Then add the following lines to the end of your shell startup file.
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export PROJECT_HOME=$HOME/Devel
source /usr/local/bin/virtualenvwrapper.sh
Note: The VIRTUALENVWRAPPER_PYTHON variable points to the normal installation location for Python3, and source /usr/local/bin/virtualenvwrapper.sh points to the normal location of the virtualenvwrapper.sh script. If the virtualenv doesn't work when you test it, one thing to check is that Python and the script are in the expected location (and then change the startup file appropriately).
For example, one installation test on macOS ended up with the following lines being necessary in the startup file:
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/Library/Frameworks/Python.framework/Versions/3.7/bin/python3
export PROJECT_HOME=$HOME/Devel
source /Library/Frameworks/Python.framework/Versions/3.7/bin/virtualenvwrapper.sh
You can find the correct locations for your system using the commands which virtualenvwrapper.sh and which python3.
These are the same lines as for Ubuntu, but the startup file is the differently named hidden file .bash_profile in your home directory.
Note: If you can't find .bash_profile to edit in the finder, you can also open this in the terminal using nano.
The commands look something like this:
cd ~ # Navigate to my home directory
ls -la #List the content of the directory. YOu should see .bash_profile
nano .bash_profile # Open the file in the nano text editor, within the terminal
# Scroll to the end of the file, and copy in the lines above
# Use Ctrl+X to exit nano, Choose Y to save the file.
Then reload the startup file by making the following call in the terminal:
source ~/.bash_profile
At this point, you may see a bunch of scripts being run (the same scripts as for the Ubuntu installation). You should now be able to create a new virtual environment with the mkvirtualenv command.
Windows 10 virtual environment setup
Installing virtualenvwrapper-win is even simpler than setting up virtualenvwrapper because you don't need to configure where the tool stores virtual environment information (there is a default value). All you need to do is run the following command in the command prompt:
pip3 install virtualenvwrapper-win
Now you can create a new virtual environment with the mkvirtualenv command
Creating a virtual environmentSection
Once you've installed virtualenvwrapper or virtualenvwrapper-win then working with virtual environments is very similar on all platforms.
Now you can create a new virtual environment with the mkvirtualenv command. As this command runs you'll see the environment being set up (what you see is slightly platform specific). When the command completes the new virtual environment will be active — you can see this because the start of the prompt will be the name of the environment in brackets (below we show this for Ubuntu, but the final line is similar for Windows/macOS).
$ mkvirtualenv my_django_environment
Running virtualenv with interpreter /usr/bin/python3
...
virtualenvwrapper.user_scripts creating /home/ubuntu/.virtualenvs/t_env7/bin/get_env_details
(my_django_environment) ubuntu@ubuntu:~$
Now you're inside the virtual environment you can install Django and start developing.
Note: From now on in this article (and indeed the module) please assume that any commands are run within a Python virtual environment like the one we set up above.
Using a virtual environmentSection
There are just a few other useful commands that you should know (there are more in the tool documentation, but these are the ones you'll use regularly):
deactivate — Exit out of the current Python virtual environment
workon — List available virtual environments
workon name_of_environment — Activate the specified Python virtual environment
rmvirtualenv name_of_environment — Remove the specified environment.
设置python 虚拟环境 virtualenv django 虚拟环境的更多相关文章
- Python创建virtualenv(虚拟环境)方法
本文目录 一 前言 二 通过virtualenv软件创建 三 在pycharm下创建 新建项目 四 已有项目使用和创建虚拟环境 五 参数说明 一 前言 需求: --公司之有一台服务器 ...
- Linux环境下虚拟环境virtualenv安装和使用
virtualenv用于创建独立的Python环境,多个Python相互独立,互不影响,它能够: 1. 在没有权限的情况下安装新套件 2. 不同应用可以使用不同的套件版本 3. 套件升级不影响其他应用 ...
- Linux环境下虚拟环境virtualenv安装和使用(转)
virtualenv用于创建独立的Python环境,多个Python相互独立,互不影响,它能够: 1. 在没有权限的情况下安装新套件 2. 不同应用可以使用不同的套件版本 3. 套件升级不影响其他应用 ...
- python 全栈开发,Day86(上传文件,上传头像,CBV,python读写Excel,虚拟环境virtualenv)
一.上传文件 上传一个图片 使用input type="file",来上传一个文件.注意:form表单必须添加属性enctype="multipart/form-data ...
- Linux下安装python虚拟环境(virtualenv,vritulaenvwrapper)
一.virtualenv virtualenv是如何创建"独立"的Python运行环境的呢? 原理很简单,就是把系统Python复制一份到virtualenv的环境,用命令sour ...
- Centos7 python虚拟环境virtualenv和virtualenvwrapper简单介绍
我的系统版本是 [root@localhost ~]# cat /etc/os-release 我的Python版本是 [root@localhost ~]# python3 -V 关于如何安装Pyt ...
- python 1.使用djano前的提前准备:虚拟环境 virtualenv
首先想要学习django我们就得了解一下虚拟环境,什么是虚拟环境?他有什么用? 1.首先虚拟环境就相当于一个一个的盒子,这个盒子里面安装的软件不会对其他的盒子造成任何影响. 2.如果你现在用Djang ...
- Python - Virtualenv 创建虚拟环境
Virtualenv 回到顶部 为了解决各个项目的共同依赖同一个环境,造成版本冲突等,virtualenv创建一个干净的环境,在这个环境下,进行Python项目的开发等,就成为一个个独立的项目,从而避 ...
- python学习--Django虚拟环境搭建
一 . 为什么选择搭建虚拟环境 搭建一个只对本次项目有用的虚拟环境,而不影响主环境 二 . 安装前准备 # 1. 安装 python # 2. 安装virtualenvwrapper # ...
随机推荐
- Win11右键菜单怎么修改为传统Win10右键风格?
前言 对于开发者而言,右键菜单会集成一些功能,升级 Win11 的右键菜单反而对开发造成不便,所以修改回传统风格. 修改成果如下 两个步骤改回传统右键风格 第一步:首先用鼠标右键点击开始菜单,选择 w ...
- vue+element ui后台遇到的坑
今天在用elementui做后台系统,遇到第一个坑:分页显示的是英文 按照官网组件复制下来的代码: <el-row :gutter="0" style="margi ...
- LeetCode-047-全排列 II
全排列 II 题目描述:给定一个可包含重复数字的序列 nums ,按任意顺序 返回所有不重复的全排列. 示例说明请见LeetCode官网. 来源:力扣(LeetCode) 链接:https://lee ...
- Linux CentOS7.X-安装jdk
一.下载 jdk 的 tar 包 网址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.h ...
- CentOS 7.5关闭FireWall 和SELinux图文详解
CentOS 7.5关闭FireWall 和SELinux图文详解 1. 环境 CentOS 7.5 2. 关闭FireWall和SELinux 2.1 FireWall 使用systemctl st ...
- 程序语言与编程实践2-> 蓝桥杯C/C++备赛记录1 | 入门了解与首周训练
寒假前班主任帮我们报了名,是得好好准备准备.作为一个CSer,coding能力一定不能太弱.我反思,好久没写C/C++代码了,净是些随手写的python脚本,刚开始上手题目bug一大堆. 由于也不是啥 ...
- Python时间处理,datetime中的strftime/strptime+pandas.DataFrame.pivot_table(像groupby之类 的操作)
python中datetime模块非常好用,提供了日期格式和字符串格式相互转化的函数strftime/strptime 1.由日期格式转化为字符串格式的函数为: datetime.datetime.s ...
- 35 异常机制 异常处理机制 异常处理五个关键字 try、catch、finally、throw、thorws 代码
异常处理机制 概念 抛出异常 捕获异常 异常处理五个关键字 try.catch.finally.throw.thorws 代码 // main { int a = 1; int b = 0; // 假 ...
- Excel文件导入SQL Server数据库
Excel表格的使用可谓是非常广泛,博主也简单百度了一下Excel的发展. 发展历程: 1982年 Microsoft推出了它的第一款电子制表软件-Multiplan,并在CP/M系统上大 Excel ...
- 内网渗透----Linux信息收集整理
一.基础信息收集 1.查看系统类型 cat /etc/issue cat /etc/*-release cat /etc/lsb-release cat /etc/redhat-release 2.内 ...