开发者

What are the pitfalls and workarounds when using Python virtual environments on Windows?

开发者 https://www.devze.com 2023-03-03 12:06 出处:网络
Short Description The question is not meant to ask if using virtual environments are needed, but when using Ian Bicking\'s virtualenvwhat is the best way, if any, to manage environments in Windows.If

Short Description

The question is not meant to ask if using virtual environments are needed, but when using Ian Bicking's virtualenv what is the best way, if any, to manage environments in Windows. If you have multiple ideas, please answer multiple times so the best answers can be voted up. Thanks!

Background

When developing in python, I generally try use Mac osx / bash as much as possible. However there are always projects that I am forced to use Windows on for hardware/driver support. For these projects, I tend to rely on the 'double click' method to run the modules with the registered python.exe. The use of the 'double click' is such a simple way to run multiple threads / tests at the same time, without having to open a new command prompt, drill down to the directory needed, then typing 'python.exe module.py'.

The End Goal

I would like to have a way to manage and utilize virtual environments without having to be at the command prompt (Windows only)

Wish List

1. Be able to install modules from either pip (command line) or from binaries (for those that can't be installed with pip for whatever reason).

2. Manage environments, with virtualenv.exe, from a GUI. (Create, remove, list, activate, etc...)

Research

So far I have been able to do bits and pieces of my wish list using different scripts / methods, but have yet to find a way to combine them. I was planning to combine most of these into a GUI my self, but thought it would be wise to find out if there is a good reason this doesn't exist already.

Installing binaries to a virtual environment can be done fairly easy using a script that changes what version of pytho开发者_StackOverflow中文版n is registered in Windows. I have been using the script for several months now with nothing but great results. See SO Question

Managing the environments appears to the more difficult portion.

If using bash, there is virutalenvwrapper written by Doug Hellmann. I use this when working in Mac OSX and hightly recommend it.

There is a port of this exertion into Power Shell found here but still will require a third party command prompt interface to be installed.

One of the more unique ports to windows that I have seen ports virtualenvwrapper to bat files. I have not tested this, but it would still require a the use of the command prompt. Found here

The most promising helper function I have found to date is written by Justin Driscoll. While this exact example would require the command prompt, it would be trivial to convert this to something that a python GUI could call. This was the path I was going down before I thought I should check with the masses on the best way to achieve my goal.


You might want to take a look at zc.buildout. Assuming the user has Python installed, you can double click on the bootstrap.py python script to generate the environment.

Once created, doubleclicking on bin\buildout.exe will recursively install dependencies and run any pre/post hook methods you define. zc.buildout allows you to specify platform specific dependencies and non-python dependencies. Additionally, you may define your own scripts for buildout to place into the bin\ folder. For example, the Plone team has a good article running Buildout on Windows referencing their own script bin\instance.exe

While not quite a polished as virtualenv on Mac/Linux/BSD, the same buildout environment will be created (eg. bin/buildout instead of bin\buildout.exe) achieving the cross-platform requirements you have.

0

精彩评论

暂无评论...
验证码 换一张
取 消