Over a million developers have joined DZone.

NetBeans IDE + virtualenv = Your Python Experimental Bed

DZone's Guide to

NetBeans IDE + virtualenv = Your Python Experimental Bed

· Web Dev Zone ·
Free Resource

Read this guide to learn everything you need to know about RPA, and how it can help you manage and automate your processes.

virtualenv is a tool to build sandbox(ed) or isolated Python environments. Using it you can create multiple isolated Python development environments each with their own isolated 'site-packages', which basically means giving yourself a playground which you might as well need during all the hacking. The page here http://pypi.python.org/pypi/virtualenv has a lot of details on how you can go about installing it and then creating your own sand boxes. Here is what you would do on a Ubuntu box, if you have setuptools installed:


$sudo easy_install virtualenv

Searching for virtualenv
Reading http://pypi.python.org/simple/virtualenv/
Best match: virtualenv 1.3.2
Downloading http://pypi.python.org/packages/2.5/v/virtualenv/virtualenv-1.3.2-py2.5.egg#md5=f2cd2b10b8be8b57e74cb1830fc0b504
Processing virtualenv-1.3.2-py2.5.egg
creating /home/amit/virtualenv-local/lib/python2.5/site-packages/virtualenv-1.3.2-py2.5.egg
Extracting virtualenv-1.3.2-py2.5.egg to /home/amit/virtualenv-local/lib/python2.5/site-packages
Adding virtualenv 1.3.2 to easy-install.pth file
Installing virtualenv script to /home/amit/virtualenv-local/bin

Installed /home/amit/virtualenv-local/lib/python2.5/site-packages/virtualenv-1.3.2-py2.5.egg
Processing dependencies for virtualenv
Finished processing dependencies for virtualenv

Creating a isolated Python environment:
$ virtualenv --no-site-packages virtual-env-1
virtualenv --no-site-packages virtual-env-1
New python executable in virtual-env-1/bin/python
Installing setuptools............done.

The above command creates a new Python virtualenv with the name 'virtual-env-1' under your pwd. Couple of things to note:
  • --no-site-packages: This option makes sure that when you are using the Python interpreter, it will *not* look into the global site-packages for third party packages (See this discussion for more on this topic)
  • setuptools is installed automatically, so that you can start doing a easy_install (and more) in your Python environment just created
Okay, so your sandbox is ready. Let us see, what is in there:
|-- bin
| |-- activate
| |-- activate_this.py
| |-- easy_install
| |-- easy_install-2.5
| `-- python
|-- include
| `-- python2.5 -> /usr/include/python2.5
`-- lib
`-- python2.5
|-- UserDict.py -> /usr/lib/python2.5/UserDict.py
|-- UserDict.pyc -> /usr/lib/python2.5/UserDict.pyc
|-- codecs.py -> /usr/lib/python2.5/codecs.py
|-- codecs.pyc -> /usr/lib/python2.5/codecs.pyc
|-- config -> /usr/lib/python2.5/config
|-- copy_reg.py -> /usr/lib/python2.5/copy_reg.py
|-- copy_reg.pyc -> /usr/lib/python2.5/copy_reg.pyc
|-- distutils
| |-- __init__.py
| |-- __init__.pyc
| `-- distutils.cfg
|-- encodings -> /usr/lib/python2.5/encodings
|-- fnmatch.py -> /usr/lib/python2.5/fnmatch.py
|-- fnmatch.pyc -> /usr/lib/python2.5/fnmatch.pyc
|-- lib-dynload -> /usr/lib/python2.5/lib-dynload
|-- locale.py -> /usr/lib/python2.5/locale.py
|-- locale.pyc -> /usr/lib/python2.5/locale.pyc
|-- no-global-site-packages.txt
|-- ntpath.py -> /usr/lib/python2.5/ntpath.py
|-- ntpath.pyc -> /usr/lib/python2.5/ntpath.pyc
|-- orig-prefix.txt
|-- os.py -> /usr/lib/python2.5/os.py
|-- os.pyc -> /usr/lib/python2.5/os.pyc
|-- posixpath.py -> /usr/lib/python2.5/posixpath.py
|-- posixpath.pyc -> /usr/lib/python2.5/posixpath.pyc
|-- re.py -> /usr/lib/python2.5/re.py
|-- re.pyc -> /usr/lib/python2.5/re.pyc
|-- site-packages
| |-- easy-install.pth
| |-- setuptools-0.6c9-py2.5.egg
| `-- setuptools.pth
|-- site.py
|-- site.pyc
|-- sre.py -> /usr/lib/python2.5/sre.py
|-- sre.pyc -> /usr/lib/python2.5/sre.pyc
|-- sre_compile.py -> /usr/lib/python2.5/sre_compile.py
|-- sre_compile.pyc -> /usr/lib/python2.5/sre_compile.pyc
|-- sre_constants.py -> /usr/lib/python2.5/sre_constants.py
|-- sre_constants.pyc -> /usr/lib/python2.5/sre_constants.pyc
|-- sre_parse.py -> /usr/lib/python2.5/sre_parse.py
|-- sre_parse.pyc -> /usr/lib/python2.5/sre_parse.pyc
|-- stat.py -> /usr/lib/python2.5/stat.py
|-- stat.pyc -> /usr/lib/python2.5/stat.pyc
|-- types.py -> /usr/lib/python2.5/types.py
`-- types.pyc -> /usr/lib/python2.5/types.pyc

10 directories, 45 files
The directory tree is pretty straight forward and spend some time looking at it. Now you can do two things:
  • Make this the default Python interpreter, using 'activate_this.py'
  • or, simply refer to it using the full pathname, such as : ~/virtual-env-1/bin/python

Using 'virtualenv' on NetBeans IDE for Python:

Coming to the main focus of this post, you can use your newly created virtualenv with the NetBeans IDE for Python. Just add a new platform using Tools > Python Platforms > New


Once added, you can verify the Python Path: 

Now, you can either make it the default platform or make your use of this platform for your selected experimental projects!

Your Python test bed is ready!

Get the senior executive’s handbook of important trends, tips, and strategies to compete and win in the digital economy.


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}