💻VIEN is a command-line tool for managing Python Virtual Environments.

Overview

PyPI version shields.io Generic badge Generic badge

vien

VIEN is a command-line tool for managing Python Virtual Environments.

It provides one-line shortcuts for:

  • creating and deleting environments
  • running commands inside environments
  • switching between environments in bash shell

Switching between projects should be simple. Creating environments for the projects should be simple too.

Ideally it's a short command that I would type even half asleep.

Something like

$ vien create 
$ vien shell

Not like

$ python3 -m venv ./where/to/put/this/.venv
$ source /i/lost/that/.venv/bin/activate
Ready-made solutions did not help.
  • pipenv kind of solved the problem, but brought new challenges unrelated to virtual environments
  • virtualenvwrapper name is easier to copy-paste than to type. And its commands are too

So there is the vien. A tool for a half asleep developer.

Install

vien requires Python 3.7+ on Linux or macOS.

Get a working Python ≥3.7, pip3 and venv.

@ Ubuntu

$ sudo apt install -y python3 python3-pip python3-venv

@ macOS

$ brew install python3

Check it works

$ python3 --version             # python shows its version
$ python3 -m venv --help        # venv shows help message
$ pip3 install --upgrade pip    # pip upgrades itself

Then:

$ pip3 install vien

Make sure it installed:

$ vien      # shows help

Upgrade it later:

$ pip3 install vien --upgrade

Use

Example: interactive shell

$ cd /path/to/myProject
$ vien create
$ vien shell

Example: running commands

$ cd /path/to/myProject
$ vien create
$ vien run pip install --upgrade pip
$ vien run pip install requests lxml
$ vien call main.py

"create" command

vien create сreates a virtual environment that will correspond the project directory. Subsequent calls to vien with the same project directory will use the same virtual environment.

$ cd /abc/myProject
$ vien create 

By default, the current working directory is assumed to be the project directory. You can override this with -p argument.

$ vien -p /abc/myProject create 

The -p argument works with all commands, not only create.

$ cd /other/working/dir
$ vien -p /abc/myProject create
$ vien -p /abc/myProject shell

"create": choose the Python version

If you have several versions of Python installed, then virtual environments can help you switch not only between dependencies, but also between interpreters.

$ cd /abc/my_old_project
$ vien run python --version  # 3.7  

$ cd /abc/my_newer_project
$ vien run python --version  # 3.9 

A project directory can be bound to only one specific interpreter.

To indicate which interpreter to use with the project, provide an argument pointing the executable.

$ vien create /usr/local/opt/[email protected]/bin/python3

In many cases, a shorter command will also work. If the needed interpreter can be executed in the shell as python3.8, you can try

$ vien create python3.8

When create is called with no argument, vien will use the Python interpreter that is running vien itself. For example, if you used Python 3.9 to pip install vien, then it is the Python 3.9 runs vien, and this Python 3.9 will be used in the virtual environment.

"shell" command

vien shell starts interactive bash session in the virtual environment.

$ cd /path/to/myProject
$ vien shell

(myProject)$ _

Now you are inside the virtual environment.

(myProject)$ which python3             # now we are using separate copy of Python
(myProject)$ echo $PATH                # everything is slightly different

(myProject)$ pip3 install requests     # installs packages into virtual environment
(myProject)$ python3 use_requests.py   # runs inside the virtual environment

Get out of the virtual environment:

(myProject)$ exit

$ _

Now you're back.

With shell pipes, you can specify what the shell should execute right in the command line.

$ echo 'which python3 && echo $PATH' | vien shell

"run" command

vien run COMMAND runs a shell command in the virtual environment.

$ cd /path/to/myProject
$ vien run python3 use_requests.py arg1 arg2  # runs script in virtual environment
$ vien run pip3 install requests              # installs packages into virtual environment
is an equivalent to
$ cd /path/to/myProject

$ source /path/to/the/venv/bin/activate
$ python3 use_requests.py arg1 arg2
$ /path/to/the/venv/bin/deactivate

$ source /path/to/the/venv/bin/activate
$ pip3 install requests
$ /path/to/the/venv/bin/deactivate

"call" command

vien call PYFILE executes a .py script in the virtual environment.

"call": running file as a file

$ cd /abc/myProject
$ vien call pkg/module.py
  
# runs [python pkg/module.py]

"call": running file as a module

If the .py file name is preceded by the -m argument, we will run it with python -m MODULE. Running in this manner often simplifies importing other modules from the program.

$ cd /abc/myProject
$ vien call -m /abc/myProject/pkg/sub/module.py

# runs [python -m pkg.sub.module]
# project dir: /abc/myProject
# working dir: /abc/myProject
  • module.py must be located somewhere inside the /abc/myProject
  • parent subdirectories such as pkg and sub must be importable, i.e. must contain __init__.py
  • the project directory will be inserted into $PYTHONPATH, making pkg.sub.module resolvable from /abc/myProject to a file

The project directory can be specified not only by the working directory, but also by the -p argument.

The call command only accepts .py files, no module names.

# ERROR: there is no file named pkg.module
$ vien call -m pkg.module 

"call": passing arguments to Python and to the program

Arguments following the call command are passed to the python executable.

$ vien call -B -OO -m package/main.py arg1 arg2  

# runs [python -B -OO -m package.main arg1 arg2]

"call": project directory

The optional -p argument can be specified before the call word. It allows you to set the project directory relative to the parent directory of the file being run.

$ cd /far/away
$ vien -p /abc/myProject call -m /abc/myProject/pkg/sub/module.py

# runs [python -m pkg.sub.module]
# project dir: /abc/myProject
# working dir: /far/away
$ cd /far/away
$ vien -p ../.. call -m /abc/myProject/pkg/sub/module.py

# runs [python -m pkg.sub.module]
# project dir: /abc/myProject  (/abc/myProject/pkg/sub/../..)
# working dir: /far/away
$ cd /abc/myProject/pkg
$ vien -p ../.. call -m sub/module.py

# runs [python -m pkg.sub.module]
# project dir: /abc/myProject  (/abc/myProject/pkg/sub/../..)
# working dir: /abc/myProject/pkg

"delete" command

vien delete deletes the virtual environment.

$ cd /path/to/myProject
$ vien delete 

"recreate" command

vien recreate old and creates new virtual environment.

If you decided to start from scratch:

$ cd /path/to/myProject
$ vien recreate 

If you decided to change the Python version:

$ cd /path/to/myProject
$ vien recreate /usr/local/opt/[email protected]/bin/python3

--project-dir, -p

This option must appear after vien, but before the command.

vien -p /abc/myProject create ...
vien -p /abc/myProject run ...
vien -p /abc/myProject shell ...

If --project-dir is specified, it is the project directory.

If --project-dir is not specified, then all commands assume that the current working directory is the project directory.

The next two calls use the same project directory and the same virtual environment. However, the working directory is different.

cd /abc/myProject
vien run python3 /abc/myProject/main.py
cd /any/where
vien -p /abc/myProject run python3 /abc/myProject/main.py

If --project-dir is specified as a relative path, its interpretation depends on the command.

  • For the call command, this is a path relative to the parent directory of the .py file being run
  • For other commands, this is a path relative to the current working directory

Virtual environments location

By default, vien places virtual environments in the $HOME/.vien directory.

project dir virtual environment dir
/abc/thisProject $HOME/.vien/thisProject_venv
/abc/otherProject $HOME/.vien/otherProject_venv
/moved/to/otherProject $HOME/.vien/otherProject_venv

Only the local name of the project directory matters.

If you're not happy with the default, you can set the environment variable VIENDIR:

$ export VIENDIR="/x/y/z"

So for the project aaa the virtual environment will be located in /x/y/z/aaa_venv.

The _venv suffix tells the utility that this directory can be safely removed.

Shebang

On POSIX systems, you can make a .py file executable, with vien executing it inside a virtual environment.

Insert the shebang line to the top of the file you want to run. The value of the shebang depends on the location of the file relative to the project directory.

File Shebang line
myProject/runme.py #!/usr/bin/env vien -p . call -m
myProject/pkg/runme.py #!/usr/bin/env vien -p .. call -m
myProject/pkg/subpkg/runme.py #!/usr/bin/env vien -p ../.. call -m

After inserting the shebang, make the file executable:

$ chmod +x runme.py  

Now you can run the runme.py directly from command line. This will use the virtual environment associated with the myProject. The working directory can be anything.

# runs the runme.py in virtual environment for myProject

$ cd anywhere/somewhere
$ /abc/myProject/pkg/main.py   

Shell prompt

By default the vien shell adds a prefix to the $PS1 bash prompt.

[email protected]$ cd /abc/myProject
[email protected]$ vien shell

(myProject)[email protected]$ _

So you can see, which virtual environment you're using.

If you customized your PS1, it may not work as expected.

personalized:prompt> cd /abc/myProject
personalized:prompt> vien shell

(myProject)[email protected]$ _

It can be fixed by providing PS1 variable to vien like that:

personalized:prompt> cd /abc/myProject
personalized:prompt> PS1=$PS1 vien shell

(myProject)personalized:prompt> _

To avoid doing this each time, export your PS1 to make it available for subprocesses.

You might also like...
PwnWiki command line searching tool & bindings written in Python
PwnWiki command line searching tool & bindings written in Python

pwsearch PwnWiki 数据库搜索命令行工具。 安装 您可以直接用 pip 命令从 PyPI 安装 pwsearch: pip3 install -U pwsearch 您也可以 clone 该仓库并直接从源码启动

PyArmor is a command line tool used to obfuscate python scripts

PyArmor is a command line tool used to obfuscate python scripts, bind obfuscated scripts to fixed machine or expire obfuscated scripts.

A command line tool (and Python library) for archiving Twitter JSON

A command line tool (and Python library) for archiving Twitter JSON

Unofficial Open Corporates CLI: OpenCorporates is a website that shares data on corporations under the copyleft Open Database License. This is an unofficial open corporates python command line tool.
Unofficial Open Corporates CLI: OpenCorporates is a website that shares data on corporations under the copyleft Open Database License. This is an unofficial open corporates python command line tool.

Unofficial Open Corporates CLI OpenCorporates is a website that shares data on corporations under the copyleft Open Database License. This is an unoff

Professor Wordlist is a free open source command line tool written in python

Professor Wordlist is a free open source command line tool written in python, With the aim of generating custom wordlists with a variety of unique parameters and functions providing many possibilities.

A simple command line tool written in python to manage a to-do list

A simple command line tool written in python to manage a to-do list Dependencies: python Commands: todolist (-a | --add) [(-p | --priority)] [(-l | --

A command line tool made in Python for the popular rhythm game
A command line tool made in Python for the popular rhythm game

osr!name A command line tool made in Python for the popular rhythm game "osu!" that changes the player name of a .osr file (replay file). Example: Not

spotifytools is a Python command line tool

spotifytools spotifytools is a Python command line tool Documentation The documentation is available on the following link Releases Instalation instru

Releases(8.1.4)
Random scripts and other bits for interacting with the SpaceX Starlink user terminal hardware

starlink-grpc-tools This repository has a handful of tools for interacting with the gRPC service implemented on the Starlink user terminal (AKA "the d

270 Dec 29, 2022
Tools crack instagram + fb ayok dicoba keburu premium 😁

FITUR INSTALLASI [1] pkg update && pkg upgrade [2] pkg install git [3] pkg install python [4] pkg install python2 [5] pkg install nano [6]

Jeeck 1 Dec 11, 2021
Fylm is a wonderful automated command line app for organizing your film media.

Overview Fylm is a wonderful automated command line app for organizing your film media. You can pronounce it Film or File 'em, whichever you like! It

Brandon Shelley 30 Dec 05, 2022
ICMP Reverse Shell written in Python 3 and with Scapy (backdoor/rev shell)

icmpdoor - ICMP Reverse Shell icmpdoor is an ICMP rev shell written in Python3 and scapy. Tested on Ubuntu 20.04, Debian 10 (Kali Linux), and Windows

Jeroen van Kessel 206 Dec 29, 2022
CLI translator based on Google translate API

Translate-CLI CLI переводчик основанный на Google translate API как пользоваться ? запустить в консоли скомпилированный скрипт (exe - windows, bin - l

7 Aug 13, 2022
Rover is a command line interface application that allows through browse through mission data, images, metadata from the NASA Official Website

🤖 rover Rover is a command line interface application that allows through browse through mission data, images, metadata from the NASA Official Websit

Saketha Ramanjam 4 Jan 19, 2022
Bear-Shell is a shell based in the terminal or command prompt.

Bear-Shell is a shell based in the terminal or command prompt. You can navigate files, run python files, create files via the BearUtils text editor, and a lot more coming up!

MichaelBear 6 Dec 25, 2021
CLI utility for updating the EVE Online static data export in a postgres database

EVE SDE Postgres updater CLI utility for updating the EVE Online static data export postgres database. This has been tested with the Fuzzwork postgres

Markus Juopperi 1 Oct 29, 2021
Python CLI utility and library for manipulating SQLite databases

sqlite-utils Python CLI utility and library for manipulating SQLite databases. Some feature highlights Pipe JSON (or CSV or TSV) directly into a new S

Simon Willison 1.1k Jan 04, 2023
A clone of the popular online game Wordle

wordle_clone A CLI application for wordle. Description A clone of the popular online game Wordle.

0 Jan 29, 2022
lfb (light file browser) is a terminal file browser

lfb (light file browser) is a terminal file browser. The whole program is a mess as of now. In the feature I will remove the need for external dependencies, tidy up the code, make an actual readme, a

2 Apr 09, 2022
Ntfy - 🖥️📱🔔 A utility for sending notifications, on demand and when commands finish.

About ntfy ntfy brings notification to your shell. It can automatically provide desktop notifications when long running commands finish or it can send

Daniel Schep 4.5k Jan 01, 2023
a GUI app base on warp-cli for linux

warp cloudflare gui a GUI app base on warp-cli for linux Installation read warp-cli install doc. install warp-cli and register with $ warp-cli registe

Moein Aghamirzaei 58 Jan 01, 2023
A collection of command-line interface games written in python

Command Line Interface Python Games Collection of some starter python game projects for beginners How to play these games Clone this repository git cl

Paras Gupta 7 Jun 06, 2022
Command-line tool for looking up colors and palettes.

Colorpedia Colorpedia is a command-line tool for looking up colors, shades and palettes. Supported color models: HEX, RGB, HSL, HSV, CMYK. Requirement

Joohwan Oh 282 Dec 27, 2022
Interact with Replit remotely with the Replit CLI

Replit CLI pip install repl-cli Welcome to Replit CLI! With the Replit CLI Application, you can work with your repls locally, including clone, pull,

Shuchir Jain 4 Aug 18, 2022
🦎 A NeoVim plugin for highlighting visual selections like in a normal document editor!

🦎 HighStr.nvim A NeoVim plugin for highlighting visual selections like in a normal document editor! Demo TL;DR HighStr.nvim is a NeoVim plugin writte

Pocco81 222 Jan 03, 2023
A CLI Spigot plugin manager that adheres to Unix conventions and Python best practices.

Spud A cross-platform, Spigot plugin manager that adheres to the Unix philosophy and Python best practices. Some focuses of the project are: Easy and

Tommy Dougiamas 9 Dec 02, 2022
Python CLI script to solve wordles.

Wordle Solver Python CLI script to solve wordles. You need at least python 3.8 installed to run this. No dependencies. Sample Usage Let's say the word

Rachel Brindle 1 Jan 16, 2022
A Python module and command line utility for working with web archive data using the WACZ format specification

py-wacz The py-wacz repository contains a Python module and command line utility for working with web archive data using the WACZ format specification

Webrecorder 14 Oct 24, 2022