Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Virtualenv

Lance McCormick
Lance McCormick
7,553 Points

Setting up a Local Python (3.4.3) Environment on Linux (Mint 17.3) Guide? Please help.

Can we post a guide to setting up a Local Python Environment using virtualenv for Linux (I am using Mint 17.3 Cinnamon 64-bit).This is where I do all my coding and I don' see why Linux would be left out of the discussion.

I have done a lot of googling and I cannot for the life of me find a proper setup guide. Linux Mint comes with Python 3.4.3, pip3 is installed, I installed virtualenv using pip3. Next, I made a empty project folder, set my directory to that new project folder, and attempted to create a new virtual environment.

I entered the command [$ virtualenv mynewvirtenv ] But it doesn't work. I get a message back from the terminal saying [ bash: /usr/bin/virtualenv: No such file or directory ]

Anyone have a solid guide that I can follow step by step? Please, if you can, cover each step I will need to take in moderate detail.

3 Answers

Pepe Suarez
Pepe Suarez
18,267 Points

Hey Lance! You should check out Virtual Env Wrapper! It will make your life a lot easier and to make virtual environments fast and flexible. Here it the link to the Docs so you can get it running! virtualenvwrapper

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

What happens if you do python -m venv mynewvirtualenv?

Lance McCormick
Lance McCormick
7,553 Points

I didn't see your post! However I did get virtualenvwrapper working! I just need clarification on how exactly I should go about installing newer versions of Python into those virtual environments. Right now my default virtual environments are created with Python 3.4.3. Please see my other post on this page for a longer explanation. Thanks Kenneth!

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

I haven't used virtualenvwrapper in quite awhile so I can't answer much about that. For the venv module, though, it should use the same Python version that you created it with. I'm not sure why you'd get more than one version of Python inside of the virtualenv.

Did you check each of the executables to see what version they are? python --version or python3 --version or whatever is in there?

Lance McCormick
Lance McCormick
7,553 Points

After hours of searching I finally figured it out. I am a Linux (Mint) new user, so I had to figure out how to build Python from source, for example lets say Python3.5. Once I did that, it installed locally and did not overwrite my OS default python versions. I tried creating a virtual environment using that python version and it threw some errors referencing some development libraries.... fast forward a couple hours of researching, I installed the ones i needed, rebooted and BAM it worked! I was super happy. So now I can use any version of Python I build from source (if I need) and keep them organized with virtual environments. Just a side note: I use virtualenvwrapper just because its the first one I figured out even though it sits on top of virtualenv. I appreciate all the help. I am thinking about posting a guide of my process and experience along with the errors I encountered with the solutions I found.

I dont know much about venv, is there something you recommend over virtualenvwrapper since you dont use it?

Thanks all!

Lance McCormick
Lance McCormick
7,553 Points

Thank you so much Pepe! It took me a few hours but after I got all the right things installed. The documentation helped a lot to see what I should be looking for from certain sources of information. I found an extremely helpful Youtube video that went over the setup process and commands. I finally have a virtual environment up and running (with a project folder for my code.)

The most difficult thing for me was the .bashrc file I had to create since Linux Mint does not have one by default in the Home directory and I am still a Linux newbie coming from Windows. Then I had to figure out how to tell it to use python3 in that .bashrc file. And then set the paths up for the virtual environments location and project location (The DOCS helped me a ton)

Then learning what is and how to "source" a file (my basic understanding is that it reads and executes a file) This .bashrc script file basically configured virtualenvwrapper and created some files for me automatically. So the learning curve here was just to understand what these commands were doing in this script file.

One thing I noticed was that when I create a new virtual environment, it places Python 3 AND Python (2) in there as well. I wonder why this is? Backwards compatibility? I am not sure.

I also managed to install Django using pip3 in one of my virtual environments isolated from the others. Which is the whole point of virtual environments obviously. (To isolate dependencies on a per project basis)

My only question is. HOW do I install a new version of Python 3 in its own environment??? When I create a new env it automatically creates it for Python 3.4.3

Do I create a new env, download and install a desired version of Python? If I am in my newly created env will it only upgrade my env? OR do I run a python upgrade terminal command of some type while in my new env? Its still a bit confusing? If any of you have some answers that would be much appreciated. Thanks!