前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Python use Virtualenv create a stand-alone environment.

Python use Virtualenv create a stand-alone environment.

作者头像
李郑
发布2020-02-17 08:37:09
6070
发布2020-02-17 08:37:09
举报
文章被收录于专栏:漫漫全栈路

Virtualenv

Virtualenv is the virtual environment of python.

It can provide a stand-alone operating environment for a python program or script.

Let’s get started.

Install and Using

Install

Install and Using Virtualenv is very simple.

代码语言:javascript
复制
> pip install virtualenv

Just type in above command in shell, ‘virtualenv’ will be installed immediately.

Tip: For well-known reasons, some python resource packs cannot be downloaded in the country. If you’re experiencing some error stoin, you should to try a scientific way to connect to the Internet.

Activate Command

After the installation is complete. We could just try how to use Virtualenv to create a stand-alone operating environment.

let’s say we’re going to develop a new project that requires a stand-alone Python operating environment, so you can:

代码语言:javascript
复制
# create a directory
> mkdir testProject
> cd testProject

# create a stand-alone Python running environment
# named testVenv:
> virtualenv --no-site-packages testVenv

The Command ‘virtualenv xxx’ is already could create a stand-alone python operating environment. We add the parameters ‘–no-site-packages’ here for keep sure that don’t copy any third-party packages to this environment.

When the shell says ‘Done’, a stand-alone environment is created.

The way to enter the environment varies depending on the operating system.

Linux or MacOS

In Linux or MacOS, you can enter this stand-alone python operating environment simply by using the “Activate” command.

When you enter the environment, the name of the current environment (testVenv) appears at the beginning of the command line for differentiation.

Windows

In Windows, we typically use ‘cmd’ or ‘powershell’ to operate commands. And their operating command are different.

In cmd mode, we still go to the directory and then execute ‘Activate’.

But in powershell mode, we need to execute a policy change first, and then execute ‘activate.ps1’ script to get into a stand-alone environment.

Make sure the current powershell window is under administrator privileges. And here’s the modification command.

代码语言:javascript
复制
# change policy
PS> Set-ExecutionPolicy RemoteSigned
# enter in environment
PS> cd D:\Code\testProject\testVenv\Scripts
PS> .\activate.ps1 
(testVenv) PS>

Some paths in the above sample code have been hidden.

Deactivate

Enter the “deactivate” command directly to shut down the current environment.

Isn’t it very simple? It’s easy to isolate different python environments and avoid them interfering with each other.

In the end

This is my first English technology blog, after which I will try to use English to record all the blogs. I hope it can help me improve my English skill.

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020-02-07,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Virtualenv
  • Install and Using
    • Install
      • Activate Command
        • Linux or MacOS
          • Windows
            • Deactivate
            • In the end
            领券
            问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档