Before we start with the tutorial I would like to tell you the story how I realized that I need a reminder on how to set up virtualenvwrapper on top of virtualenv in Ubuntu 18.04. I have done this process several of times on different computers and every time it seemed to be just a little bit different than before.
Recently I got myself a new laptop and I on my way home I have read several tutorials on “How to set up virtualenvwrapper on Ubuntu 18.04”. And let me tell you that it seems really easy because all of those tutorials are pretty straight forward and basically explain how to do the next three 3 things:
Install virtualenv
Install virtualenvwrapper
Edit .bashrc/.bash_profile or both
But even though all these tutorials are meant to help us set up virtualenvwrapper on a modern Ubuntu 18.04 installation non of them worked for me.
I had several errors while trying to figure out what went wrong while following these tutorials. First I’ve had some of “mkvirtualenv: command not found”, then a little of “-bash: /usr/bin/virtualenvwrapper.sh: No such file or directory”, and then a touch of “ERROR: virtualenvwrapper could not find virtualenv in your path”.
After some research I realized that all virtualenvwrapper Ubuntu 18.04 tutorials are copies an old text written before April 2016 (release date of Ubuntu 16.04). And I know it to be true because from Ubuntu 16.04 and onward the location for the vritualenvwrapper’s pip installation has changed from /usr/local/bin/virtualenvwrapper.sh to ~/.local/bin/virtualenvwrapper.sh.Note that the local directory is hidden.
So let’s start by writing a tutorial that will show you how to avoid all those issues mentioned above.
Prerequisites
In this text I will show you how to set up virtualenvwrapper with pip3 (pip for Python 3). I chosen this version of pip instead of a Python 2 version because Python’s 2 end of life is January 1. 2020.
To complete this tutorial you will need a computer with Ubuntu 18.04 installed and a internet connection :) Also some knowledge in terminals and Vim editor would be useful. We will assume you already updated and upgraded the system.
Setting up a Virtual Environment
Now open your terminal in the home directory by right clicking and choosing the option “Open in Terminal” or you can press the CTRL, ALT, and T keys on your keyboard at the same time to open the Terminal application automatically.
You first need to create a special directory that will hold all of your virtual environments so proceed with creating a new hidden directory called virtualenv.
mkdir .virtualenv
Now you should install pip for Python3.
sudo apt install python3-pip
Confirm the pip3 installation.
pip3 --version
Now install virtualenv via pip3.
pip3 install virtualenv
To find out the location where your virtualenv was installed type:
which virtualenv
Install virtualenvwrapper via pip3:
pip3 install virtualenvwrapper
We are going to modify your .bashrc file by adding a row that will adjust every new virtual environment to use Python 3. We will point virtual environments to the directory we created above (.virtualenv) and we will also point to the locations of the virtualenv and virtualenvwrapper.
Now open the .bashrc file using Vim editor.
vim .bashrc
If you still haven’t used Vim editor or you don’t have it installed on your computer you should install it now. It is one of widely used Linux editors and for a good reason.
sudo apt install vim
After you installed Vim open the file .bashrc file by typing in the vim .bashrc command in your terminal. Navigate to the bottom of the .bashrc file, press the letter i to enter the insert mode of Vim and add these rows:
After you are done, press theesc key then type:wqand press enter, this command will save and exit the Vim editor. Close and reopen your terminal when you’re done.
To create a virtual environment in Python3 and activate it immediately use this command in your terminal:
mkvirtualenv name_of_your_env
You should confirm that this environment is set up for Python3:
python -V
To deactivate the environment use the deactivate command.
deactivate
To list all available virtual environments use the command workon or lsvirtualenv (Same result as workon but shown in a fancy way) in your terminal:
workonlsvirtualenv
To activate one specific environment use workon + name of your environment:
workon name_of_your_env
There are several useful command you might need to use someday:
Rmvirtualenv will remove a specific virtual environment located in your .virtualenv directory.
rmvirtualenv name_of_your_env
Cpvirtualenv will copy the existing virtual environment to a new virtual environment and activate it.
cpvirtualenv old_virtual_env new_virtual_env
Well done!
You have now created your first isolated Python 3 environment!
You can, but it is important to select the right IRA for your needs. A Traditional (or Rollover) IRA is typically used for pre-tax assets because savings will stay invested on a tax-deferred basis and you won't owe any taxes on the rollover transaction itself. However, if you roll pre-tax assets into a Roth IRA, you will owe taxes on those funds. For after-tax assets, your options are a little more varied. You can roll the funds into a Roth IRA tax-free. You also have the option of taking the funds in cash or rolling them into an IRA along with your pre-tax savings. If you choose the latter option, it is important that you keep track of the after-tax amount so that when you start taking distributions, you'll know which funds have already been taxed. IRS Form 8606 is designed to help you do just this. Before making a decision, please consult with a tax advisor about your specific situation.
You're an inspiration, have you ever heard of Qi Lu? He is a quiet legend in Silicon Valley that also grew up in a rural village in China. He spent years working at a dock, saving up money hoping one day to work in America. He believed the one thing God made sure everyone was equal in, was the time people have in a day. He experimented with his body and realized he only needed 5 hours of sleep per day to feel awake. He spent the day time working and at night researching and writing computer science papers (this went on for years). One day by pure luck, he was able to sit in on a lecture given by a Carnegie Mellon professor who was giving a lecture on a CS topic. Lu was participating and asking very complex questions which intrigued the professor. After the talk the professor asked if Lu had done any research work and if he could show him. WIth a big smile Lu said wait one moment and brought back (I think it was 5) his research papers. The professor gave him an offer to study in America, on a full ride paid by the professor himself. This man ended up becoming a Microsoft executive, COO of Baidu (Google of China) and is now the head of Y combinator. I read this story in the book the Third Door. One of his quotes paraphrased: "Luck is like a bus, it comes and go's, the only way your going to get on is to be prepared and have your ticket" Ref: https://leetcode.com/discuss/career/458113/my-inspirational-journey-to-study-in-the-us-and-then-summer-intern-at-google
Note, your external hard drives are still there, you only need to mount them properly. For example, in my case, I have two external hard drives, one has 4T space and antoher have 2T space. I want to name them as 4T and 2Tssd, respectively. Here is how:
#step1: check the disk information, pay attention to the external drive: sudo fdisk -l #Your screen display lots of information, and you should find something like: ... Disk /dev/sda: 3.7 TiB, 4000787030016 bytes, 7814037168 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disklabel type: gpt Disk identifier: 6047D23B-339C-4AE5-90C5-C0DD7F75FE22
Device Start End Sectors Size Type /dev/sda1 2048 7814035455 7814033408 3.7T Linux filesystem
Disk /dev/sdb: 1.9 TiB, 2048408248320 bytes, 4000797360 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x93a92f38
Device Boot Start End Sectors Size Id Type /dev/sdb1 2048 4000797359 4000795312 1.9T 83 Linux
>>> c = Counter() # a new, empty counter >>> c = Counter('gallahad') # a new counter from an iterable >>> c = Counter({'red': 4, 'blue': 2}) # a new counter from a mapping >>> c = Counter(cats=4, dogs=8) # a new counter from keyword args most_common(n) 可以得到出现次数最多的 n 个数: >>> Counter('abracadabra').most_common(3) # doctest: +SKIP [('a', 5), ('r', 2), ('b', 2)]