Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I test my python module without installing it

Tags:

python

testing

I'm in the process of redesigning/refactoring my Python quantum chemistry package (pyquante). One of the things I don't like about the existing release is that I have to install the package to run the test suite. That is, the test suite has statements like from PyQuante import SCF, and, of course, this PyQuante could refer to the installed version or a local version.

I know about virtualenv, and realize this is an option for me. But I was wondering whether anything else might be appropriate. In the past I've hacked sys.path for things like this, and have been told by better Python programmers that I shouldn't ever to this.

Does anyone have any suggestions for how I can do this? The point is that I want to test the current version of the code without installing it.

Thanks in advance for anyone who can see through my babbling and offer suggestions!

like image 415
Rick Avatar asked Apr 15 '11 13:04

Rick


People also ask

How do I use Python modules without installing?

If you are not able to install modules on a machine(due to not having enough permissions), you could use either virtualenv or save the module files in another directory and use the following code to allow Python to search for modules in the given module: >>> import os, sys >>> file_path = 'AdditionalModules/' >>> sys.

Can I run Python without pip?

To install any python library without pip command, we can download the package from pypi.org in and run it's setup.py file using python. This will install the package on your system.

How do you check if a Python module is installed or not?

To check all the installed Python modules, we can use the following two commands with the 'pip': Using 'pip freeze' command. Using 'pip list command.


2 Answers

Create a proper package for your stuff and use

python setup.py develop

to make it a proper dev-package.

See:

  • https://stackoverflow.com/a/19048754/548039
  • http://setuptools.readthedocs.io/en/latest/setuptools.html#development-mode
like image 123
Andreas Jung Avatar answered Sep 18 '22 12:09

Andreas Jung


I would honestly insist on using virtualenv, its designed for this exact reason in mind. very small overhead, and if you ever mess up just delete directory. I am sure as you grow, things won't be as simple as they are now for your current situation. Take it as an opportunity to learn.

like image 41
myusuf3 Avatar answered Sep 21 '22 12:09

myusuf3