原创

在Virtualenv中使用Idle

本文适用于Linux系统,在DebianTesting上测试通过。

关于Virtualenv

先看一段Virtualenv这货的官方介绍

virtualenv is a tool to create isolated Python environments.

The basic problem being addressed is one of dependencies and versions, and indirectly permissions. Imagine you have an application that needs version 1 of LibFoo, but another application requires version 2. How can you use both these applications? If you install everything into /usr/lib/python2.7/site-packages (or whatever your platform’s standard location is), it’s easy to end up in a situation where you unintentionally upgrade an application that shouldn’t be upgraded.

Or more generally, what if you want to install an application and leave it be? If an application works, any change in its libraries or the versions of those libraries can break the application.

Also, what if you can’t install packages into the global site-packages directory? For instance, on a shared host.

In all these cases, virtualenv can help you. It creates an environment that has its own installation directories, that doesn’t share libraries with other virtualenv environments (and optionally doesn’t access the globally installed libraries either).

也就是说Virtualenv这货就像丫的名字,可以给用户提供一个虚拟的Python环境,这个环境里的东西独立于系统的Python设置,在这个虚拟环境里你可劲儿折腾,怎么折腾都不会有问题。

安装virtualenv也很简单:

pip install virtualenv

很多网上的教程要下载virtualenv的安装包之后手动安装,这里推荐使用pip从pypi上直接下载,可以让pip处理很多需要我们手动处理的问题。

Linux用户,推荐使用apt等包管理器安装:

sudo apt-get install virtualenv

关于VirtualenvWrapper

再看一段VirtualenvWrapper这货官方的介绍:

virtualenvwrapper is a set of extensions to Ian Bicking’s virtualenv tool. The extensions include wrappers for creating and deleting virtual environments and otherwise managing your development workflow, making it easier to work on more than one project at a time without introducing conflicts in their dependencies.

这货是辅助Virtualenv使用的,本身不能单独提供功能。

安装方式也很简单:

pip install virtualenvwrapper

推荐使用apt等包管理器安装:

sudo apt-get install virtualenvwrapper

Virtualenv中的Idle

Idle是python自带的编辑器,集编写调试于一体,在当前众多IDE百花齐放百家争鸣的盛世下,Idle或许不是最强大的IDE,但一定是最方便而且可用的,官方Python安装包已经包含了Idle,在Linux里面,只需要这样,就可以安装Idle:

sudo apt-get install idle

当然,apt仓库里面会有很多不同的Python版本,对应着也有会不同版本的Idle,请选择自己合适的版本。

新建一个vidle.py,内容如下:

#!/usr/bin/env python2
from idlelib.PyShell import main
if __name__ == '__main__':
main()

其中,idlelib就是Idle对应的库。

第一行用于告诉shell需要用什么解释器执行当前脚本,由于我们要使用Virtualenv

,所以默认的的__/usr/bin/python__在这里无法正常访问我们的Virtualenv中的python环境,而每个Virtualenv中的python可执行文件所在的目录又不尽相同,在这里,使用env去自动寻找当前环境上下文中指定的Python可执行文件。

到这里我们已经可以在Virtualenv中使用Idle,只需要创建一个Virtualenv并在这个Virtualenv里面执行这个vidle.py就可以了。

user@linux:~$ mkvirtualenv test
Running virtualenv with interpreter /usr/bin/python2
New python executable in test/bin/python2
Also creating executable in test/bin/python
Installing setuptools, pip...done.
(test)user@linux:~$ ./path/to/vidle.py

如果不想每次都带上全路径,可以在系统里面创建一个链接,指向这个文件。

sudo ln /path/to/vidle.py /usr/bin/vidle.py

将vidle.py开头的pytho2改成python3,则该脚本可用于启动python3的idle:

#!/usr/bin/env python3
from idlelib.PyShell import main
if __name__ == '__main__':
main()

在Virtualenv中使用Idle的更多相关文章

  1. python虚拟环境virtualenv、virtualenv下运行IDLE、powershell 运行脚本由执行策略引起的问题

    一.为什么要创建虚拟环境: 应为在开发中会有同时对一个包不同版本的需求,创建多个开发环境就能解决这个问题.或许也会有对python不同版本的需求,这就需要使用程序来管理不同的版本,virtualenv ...

  2. 在virtualenv中安装libxml2和libxslt

    在使用python的工作中,需要使用到libxml2和libxslt库.原来在实际环境中已经安装完成了,但是在virtualenv中还没有,现在正在整理virtualenv的环境.下面把在virtua ...

  3. [python] 2、python使用pyaudio进行录音,及其在python虚拟环境virtualenv中安装遇到的问题

    1.pyaudio安装大背景 最近在做智能音箱,需要编写声音拾取代码,我先是百度两篇比较常见的用python进行录音的操作的文章: python写一个录音小程序:http://blog.csdn.ne ...

  4. 在virtualenv中使用不同的Python版本

    来源:百度SEO公司   我有一个目前使用python 2.5.4运行的Debian系统. 我正确安装了virtualenv,一切正常. 我是否可以将virtualenv与其他版本的Python一起使 ...

  5. virtualenv中ImportError: No module named django

    问题现象:在代码py文件中,import django 报错,但是在python shell中直接执行这个语句没错, 网上搜索了下,自己测试了下,确定原因是由于使用了python中的virtualen ...

  6. virtualenv 中 install flask 的小问题

    最经在学习Python flask 框架 ,用virtualenv建立好我的flask虚拟环境后,执行 sudo pip install flask 并没有报错 我以为已经装上了flask,但当我进入 ...

  7. 填坑!!!virtualenv 中 nginx + uwsgi 部署 django

    一.为什么会有这篇文章 第一次接触 uwsgi 和 nginx ,这个环境搭建,踩了太多坑,现在记录下来,让后来者少走弯路. 本来在 Ubuntu14.04 上 搭建好了环境,然后到 centos7. ...

  8. macOS在virtualenv中使用wxPython报错

    在虚拟的Python环境中运行GUI的软件报错 This program needs access to the screen. Please run with a Framework build o ...

  9. 在Windows下的virtualenv中搭建Flask+MySQLDb开发环境

    virtualenv和Flask的安装前面已经介绍过了,这里主要讲如何在venv中安装MySQL 安装MySQLdb 下载MySQL-python-1.2.3.win32-py2.7.exe并安装. ...

随机推荐

  1. linux 高级路由

    1. 什么是高级路由? 是把信息从源穿过网络到达目的地的行为. 有两个动作:确定最佳路径,传输信息 确定最佳路径:手工指定,自动学习. 传输信息:隧道传输,流量整形 高级路由(策略路由)是根据一定的需 ...

  2. JS一个算法题

    题目:实现超出整数存储范围的两个大整数想加function(a,b).注意:参数a和b以及函数返回值都是字符串. 目的:考算法, 基本逻辑. 我实现的基本思路是: ①两个数字字符串长度补成一样,用字符 ...

  3. Linux TCP/IP调优-Linux内核参数注释

    固定文件的内核参数 下列文件所在目录: /proc/sys/net/ipv4/ 名称 默认值 建议值 描述 tcpsyn_retries 5 1 对于一个新建连接,内核要发送多少个SYN连接请求才决定 ...

  4. WPF 异步刷新页面,创建定时器

    #region 异步,刷新页面 /// <summary> /// 页面加载事件 /// </summary> /// <param name="sender& ...

  5. gentoo rtthread scons error: unknown type name 'fd_set

    手动在rtconfig.h中加人 #define HAVE_SYS_SELECT_H 就能编译过了

  6. jq-杂记

    点击消失 <script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js"> </script& ...

  7. <spark> hadoop/spark 集群搭建

    参考的这3个文档,虽然搭建花了挺长时间也遇到挺多问题,但是这3个文档对我的帮助确实挺大,如果有兴趣的或者有需要的可以参考以下文档. http://blog.csdn.net/wy250229163/a ...

  8. 使用swagger 生成 Flask RESTful API

    使用swagger 生成 Flask RESTful API http://www.voidcn.com/article/p-rcvzjvpf-e.html swagger官网 https://swa ...

  9. tkinter简单打开网址 + 执行系统命令

    from tkinter import * import webbrowser root = Tk() text = Text(root,width=30,height = 5) text.pack( ...

  10. Dagger2使用

    初衷 Dagger2的初衷就是通过依赖注入让你少些很多公式化代码,更容易测试,降低耦合,创建可复用可互换的模块.你可以在Debug包,测试运行包以及release包优雅注入三种不同的实现. 依赖注入 ...