0

On a single machine, how can/should two versions of a single python module be used

(a) simultaneously on the same machine,

(b) under a single user, and

(c) without installing external programs (cant reliably install external stuff on Windows work computer, sadly),

(d) having the same name (to allow no pains when upgrading ($ git pull newversion) )

A production version of a code project is running constantly. On the same machine, a test/development version of the code is also running periodically. How can they both use their own specific version of a given module?

Version A:

#!/usr/bin/python34
#C:\\myproject\\testversion\\bin\\myprogram.py
import mymodule  ## this version in C:\\myproject\\testversion\\lib\\python
mymodule.do_stuff() # do_stuff version A

Version B:

#!/usr/bin/python34
#C:\\myproject\\productionversion\\bin\\myprogram.py
import mymodule ## this version is in C:\\myproject\\productionversion\\lib\\python
mymodule.do_stuff() ## do_stuff version B

Strictly using the PythonPath environment variable would pick the same mymodule do for both versions, if my understanding is correct.

After reading this question about different python modules, and the python docs about modules, I feel like properly organizing a package rather than just a module may be appropriate, but I can't quite tell what best practice would be from that.

Also, since I thought standard (best?) procedure for many projects such as deb packages etc. is to have scripts in a different folder than modules (e.g. bin vs. lib), it seems that the import keyword just looking in the same directory is not sufficient for the above case.

Community
  • 1
  • 1
hilcharge
  • 1,515
  • 3
  • 12
  • 18
  • 1
    Could they be run in different virtual environments? – jonrsharpe Apr 22 '15 at 15:32
  • Use a shebang to indicate the Python version. – Malik Brahimi Apr 22 '15 at 15:33
  • "cant reliably install external stuff on Windows work computer" - you should probably quit. On a more serious note (not that I'm not serious about quiting) take a look at relative imports. Also if you run your script from \myproject\test|productionversion\ you should be able to `from lib.python import mymodule` in the `myprogram.py` file and it should work. – Ionut Hulub Apr 22 '15 at 15:37
  • Have you heard of Python Launcher for Windows? – Malik Brahimi Apr 22 '15 at 15:39
  • Can you be more specific about different virtual environments? I'm not familiar sorry. The python version is the same, only the module version is different. Havent heard of Python Launcher. – hilcharge Apr 22 '15 at 15:39
  • Different virtual environments is what you get by using `virtualenv`, which was created for this kind of problems (https://pypi.python.org/pypi/virtualenv). If you're not allowed to install that, you really should talk to your admin. – SiggiSv Apr 22 '15 at 16:11
  • perfect, looks like it will take some getting used to but it installed easily enough. – hilcharge Apr 23 '15 at 14:01

0 Answers0