Running virtualenv to set the ENV

dieter dieter at handshake.de
Thu Apr 25 02:52:08 EDT 2019


Rich Shepard <rshepard at appl-ecosys.com> writes:
> Which is the CWD for running virtualenv and spcifying the path to the
> project's directoy?

I mentioned "virtualenv" together with "setuptools".

"virtualenv" gives you a (light weight) isolated Python installation
(sharing things with the base Python installation).
You typically use "pip" to install extensions there (at least
for extensions maintained on "PyPI").

For your own project, you must learn how to make it "installable in the
standard way". "setuptools" can help with this.
With "setuptools", your project contains a "setup.py".
It uses "setuptools"'s "setup" function to handle things related to
installation, development, publishing, etc.
You typically call it with "python setup.py <command>".

My favorite "<command>" for my development is "develop". 
It "installs" the project into the Python installation
in a way that local modifications (to your project's Python code) are
automatically effective in the Python installation.
In contrast, the command "install" would copy the project
files to the Python installation such that later changes in
the project would not affect the Python installation.


"setuptools" is quite complex. You must read its documentation
(--> "https://setuptools.readthedocs.io/en/latest/")
to make effective use of it.

If you make your project "installable in the standard way",
then later installations become trivial - whether installations
in a "virtualenv", installations in a local or global Python installation,
world wide publishing...
However, you will need to invest some learning time to achieve this.
Your current structure is not yet adequate for this: e.g.
you cannot have top level packages named "classes", "model", etc.
as the risk for name clashes is far too great when combined with
other projects.


The alternative: you set up your "virtualenv" manually to learn about
your project.

A Python installation (including a "virtualenv") typically
contains the folder "site-packages" (below "lib/python<version>").
This "site-packages" is automatically put on "sys.path".
Thus, packages put there can be imported.

Put links to your folders there (if your platform supports links,
otherwise copy) or learn about Python's "*.pth" files
and put a ".pth" file there for you project.




More information about the Python-list mailing list