# Preface --- This is loosely a part 2 to my **[Getting Started with Bash on Windows](https://steemit.com/technology/@tomshwom/getting-started-with-bash-on-windows)** post. If you already have a working Python development environment, you can skip that post and continue here. <center>![](https://steemitimages.com/DQmWnk4zGe2g48okpHubji56bJPy8WsSmwtAovGyZi7ZKDY/image.png)</center> # What is a Virtual Environment? --- Virtual environments are similar to [virtual machines](https://en.wikipedia.org/wiki/Virtual_machine), but rather than emulating an entire system, virtual environments focus on a single application space for programs to run isolated from others. Virtualenv will let you run multiple versions and instances of Python at once, without letting them interfere with eachother. # Setting Up Virtualenv --- If you followed my **[Getting Started with Bash on Windows](https://steemit.com/technology/@tomshwom/getting-started-with-bash-on-windows)** post, you're ready to open up your terminal and get started. ### Getting virtualenv installed First, we want to check and see if we already have virtualenv installed. Do this by typing: ```virtualenv --version``` <center>![](https://steemitimages.com/DQmeDxshaRoRURS4cM3LXio45S9noBSE7b1o7Y4J4Zx6TUB/image.png)</center> If you didn't get a similar output to what's above, you probably don't have virtualenv installed. Install it using one of these commands: ```sudo apt-get install python-virtualenv``` <--One I'd recommend for noobies ```sudo easy_install virtualenv``` ```sudo pip install virtualenv``` Once it's installed, check to make sure by using the ```virtualenv --version``` command. ### Prepare your virtual environment Navigate to the directory where you want the virtual environment to be stored, and create a new folder to contain everything by using the ```mkdir``` command (or simply create a new folder in the file explorer). Name it something appropriate like "virtualenvironment_python_3.6". Navigate inside this folder and create your virtual environment by running: ```virtualenv my_app``` If you want to isolate the site packages, add ``` --no-site-packages``` to the end of this command. After a short wait, you can now navigate inside your "my_app" directory to the "bin" folder and activate the virtual environment by using: ```source activate``` You will see that your shell prompt now says "(my_app)" at the beginning, indicating that you are inside your virtualenv. Any packages you install using pip or easy_install will now be installed to the "my_app/lib/pythonX.X/site-packages" directory, completely isolated from other virtualenvs and your main system. Virtualenv does **not** create a new Python environment, it uses links to existing files. This means you need an active Python environment already installed on your system. ### Using your virtualenv Lets run through a small example to demonstrate things. To install a package to your virtualenv, use pip install X. No need to sudo the command since the files are being stored in the directory created by your user account. For example: ```pip install flask``` Now we can create a Python program using the Flask web framework. To keep things in the terminal, lets run VIM and write a short program. ```vim``` This should open VIM where you'll be greeted by the VIM welcome message. ```i``` to inter insert mode. If you remember the tips from my previous post, you can copy & paste what's below into your terminal next. ``` from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello World!' if __name__ == '__main__': app.run() ``` Hit the ```esc``` key, and type: ```:wq hello.py``` This will (w)rite, (q)uit, and name the file "hello.py". Now we can run our Flask program by typing: ```python hello.py``` It will inform you that the Flask app is running and on which address/port. You can now navigate to your web browser and enter this info to see your web app! <center>![](https://steemitimages.com/DQmeuzgpa2TWdDkwjU6axRWP96NCszGA91jk5KRtdngW2aS/image.png)</center> Hit ```Ctrl + C``` to shut down the Flask app when you're done. ### Closing the virtualenv When you're done using your virtualevn, simply use: ```deactivate``` Now you know how to install and use virtualenv for your Python projects! I relied heavily on the following resources for writing this short tutorial, and if you encounter any issues they should be your first reference. If you can't find what you're looking for here, feel free to leave a comment below and somebody will try to help! <center>**[Python for Beginners - How to use Python virtualenv](http://www.pythonforbeginners.com/basics/how-to-use-python-virtualenv) ••• [Flask Quickstart guide](http://flask.pocoo.org/docs/0.10/quickstart/)**</center> --- <center><sub>Leave a **like** or **resteem** if you found this helpful. You can also support me by sending ETH or ERC20 tokens to **Tomshwom.eth**. Leave your thoughts below about what you think and on which content you'd like to see in the future!</sub></center>
author | tomshwom |
---|---|
permlink | setting-up-python-virtualenv |
category | programming |
json_metadata | {"tags":["programming","python","developer","virtualenv"],"image":["https://steemitimages.com/DQmWnk4zGe2g48okpHubji56bJPy8WsSmwtAovGyZi7ZKDY/image.png","https://steemitimages.com/DQmeDxshaRoRURS4cM3LXio45S9noBSE7b1o7Y4J4Zx6TUB/image.png","https://steemitimages.com/DQmeuzgpa2TWdDkwjU6axRWP96NCszGA91jk5KRtdngW2aS/image.png"],"links":["https://steemit.com/technology/@tomshwom/getting-started-with-bash-on-windows","https://en.wikipedia.org/wiki/Virtual_machine","http://www.pythonforbeginners.com/basics/how-to-use-python-virtualenv","http://flask.pocoo.org/docs/0.10/quickstart/"],"app":"steemit/0.1","format":"markdown"} |
created | 2017-10-26 21:52:36 |
last_update | 2017-10-26 21:52:36 |
depth | 0 |
children | 5 |
last_payout | 2017-11-02 21:52:36 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 3.228 HBD |
curator_payout_value | 0.960 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 5,108 |
author_reputation | 1,713,446,395,686 |
root_title | "Setting Up Python Virtualenv" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 18,644,248 |
net_rshares | 1,905,290,101,235 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
busser | 0 | 75,316,676,311 | 100% | ||
shaka | 0 | 370,782,542,366 | 10% | ||
tomshwom | 0 | 12,114,138,034 | 100% | ||
randowhale | 0 | 1,444,925,761,036 | 9.25% | ||
st0ne | 0 | 0 | 100% | ||
not-a-bird | 0 | 1,031,034,898 | 100% | ||
smitop | 0 | 1,119,948,590 | 100% | ||
torsteoe | 0 | 0 | 100% |
another option is installing Anaconda. Below video explains the details. <iframe width="560" height="315" src="https://www.youtube.com/embed/7rYPHZ1FVQE" frameborder="0" allowfullscreen></iframe>
author | naveendavisv |
---|---|
permlink | re-tomshwom-setting-up-python-virtualenv-20171027t035314958z |
category | programming |
json_metadata | {"tags":["programming"],"app":"busy/1.0.0"} |
created | 2017-10-27 03:53:21 |
last_update | 2017-10-27 03:53:21 |
depth | 1 |
children | 0 |
last_payout | 2017-11-03 03:53:21 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 195 |
author_reputation | 32,557,718,122 |
root_title | "Setting Up Python Virtualenv" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 18,661,588 |
net_rshares | 0 |
> virtual environments focus on a single application space for programs to run isolated from others You make it sound like it's a container solution that provides process isolation. Doesn't it just provide you with an environment with all the dependencies you need to run your program?
author | not-a-bird |
---|---|
permlink | re-tomshwom-setting-up-python-virtualenv-20171031t125433492z |
category | programming |
json_metadata | {"tags":["programming"],"app":"steemit/0.1"} |
created | 2017-10-31 12:54:33 |
last_update | 2017-10-31 12:54:33 |
depth | 1 |
children | 2 |
last_payout | 2017-11-07 12:54:33 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.017 HBD |
curator_payout_value | 0.006 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 288 |
author_reputation | 4,828,771,219,503 |
root_title | "Setting Up Python Virtualenv" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 19,068,965 |
net_rshares | 12,115,001,541 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
tomshwom | 0 | 12,115,001,541 | 100% |
That is correct. It's not process isolation, just package/environment isolation.
author | tomshwom |
---|---|
permlink | re-not-a-bird-re-tomshwom-setting-up-python-virtualenv-20171031t133019635z |
category | programming |
json_metadata | {"tags":["programming"],"app":"steemit/0.1"} |
created | 2017-10-31 13:30:18 |
last_update | 2017-10-31 13:30:18 |
depth | 2 |
children | 1 |
last_payout | 2017-11-07 13:30:18 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 81 |
author_reputation | 1,713,446,395,686 |
root_title | "Setting Up Python Virtualenv" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 19,072,305 |
net_rshares | 1,829,817,775 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
not-a-bird | 0 | 1,829,817,775 | 100% |
Thanks for clearing that up. I wasn't sure if I had missed some kind of update that added container support.
author | not-a-bird |
---|---|
permlink | re-tomshwom-re-not-a-bird-re-tomshwom-setting-up-python-virtualenv-20171102t000453514z |
category | programming |
json_metadata | {"tags":["programming"],"app":"steemit/0.1"} |
created | 2017-11-02 00:05:03 |
last_update | 2017-11-02 00:05:03 |
depth | 3 |
children | 0 |
last_payout | 2017-11-09 00:05:03 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.017 HBD |
curator_payout_value | 0.005 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 109 |
author_reputation | 4,828,771,219,503 |
root_title | "Setting Up Python Virtualenv" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 19,213,651 |
net_rshares | 12,115,618,226 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
tomshwom | 0 | 12,115,618,226 | 100% |
This post received a 5.0% upvote from @randowhale thanks to @tomshwom! For more information, [click here](https://steemit.com/steemit/@randowhale/introducing-randowhale-will-you-get-the-100-vote-give-it-a-shot)!
author | randowhale |
---|---|
permlink | re-setting-up-python-virtualenv-20171029t195622 |
category | programming |
json_metadata | "{"app": "randowhale/0.1", "format": "markdown"}" |
created | 2017-10-29 19:56:24 |
last_update | 2017-10-29 19:56:24 |
depth | 1 |
children | 0 |
last_payout | 2017-11-05 19:56:24 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.024 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 212 |
author_reputation | 47,657,457,485,459 |
root_title | "Setting Up Python Virtualenv" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 18,909,027 |
net_rshares | 12,114,919,312 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
tomshwom | 0 | 12,114,919,312 | 100% |