Reputation: 4130
I have created a collection of Python scripts, to be used as tools in our dev group. The scripts have dependencies, such as requests
and flake8
(this should technically be under dev
setup, but whatever).
I have created a setup-dev.bat
file, with the idea of being a "first-use" setup.
python -m pip install --upgrade pip --user
python -m pip install --upgrade virtualenv --user
python -m venv .env
call .\.env\Scripts\Activate.bat
python -m pip install --upgrade pip --user
python -m pip install --upgrade virtualenv --user
pip install .
The idea is:
Install and/or upgrade pip
on the system
Install and/or upgrade virtualenv
on the system
Create a virtual environment .env
Activate it
Upgrade the pip
and virtualenv
under it (not sure if this makes sense at all)
'Install' the scripts - most importantly, this install the dependencies
Now the scripts are ready to use and their dependencies are contained within .env
. The idea is - if/when those scripts get distributed to the higher environments for Ops to run, I don't want to pollute their environment with my dependencies.
I should point out that those tools will never be distributed over pip
or any other system, they are for internal use within the company and will be hosted on a source control, or emailed to Operations with execution instructions.
Now my questions:
4
above I should probably run just \activate
instead of the .bat
? I guess the .env
depends on the host system and would have different contents under a different OS? Which script do I have to call to activate the environment in most OS-agnostic way? The activate
, the ps1
or the .bat
?.env\Scripts\activate
? Is there any way to semi-automate this, make it more obvious or fool-proof?You are using pip version 19.0.3, however version 19.3.1 is available.
as a result of my pip upgrade
command?!Edits:
python -m pip install --upgrade pip --user
to python -m pip install --upgrade pip
and this got rid of the error. I guess installing "for the user" under the venv
doesn't make sense anyway.virtualenv
steps, per the comment belowpip install .
to pip install -e .
to ensure that the scripts (some of which act as configurations) are still editable.I feel like I am progressing, but I am confused about the lack of posts around such setup and it feels like I am doing something wrong.
Upvotes: 3
Views: 443
Reputation: 1886
You could bundle the scripts in a wheel file (read about entry_points here) that can be installed via pip (i.e., pip install bundle.whl
; see this). With this approach, the dependencies will be part of the wheel file and pip will automatically install the dependencies when the wheel file is installed.
--user
flag to pip will install the scripts in a location local to the user as determined by the user scheme. So, if you are fine with the scripts "polluting" a user's local installation, then virtualenv is not needed.
Upvotes: 1