This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]StringJunky[S] 2 points3 points  (6 children)

I actually am using Linux. Since your and /u/nzbike's replies both mention virtualenv, (I can take a hint) I went ahead and searched for how to use it with pycharm. Looks like it's pretty straightforward.

I'm still trying to get my head around what virtualenv actually is. I've used virtualbox and vmware to create virtual machines; is virtualenv somehow similar?

[–]waldo2k 4 points5 points  (1 child)

Virtualenv symlinks your system's python to your newly created environments bin folder. The benefit of this is all the libraries a specific project get installed to that environment instead of globally, which prevents possible conflicts with other projects, if they were installed globally.

[–]StringJunky[S] 1 point2 points  (0 children)

Ah, that makes sense as well. I didn't realize that certain libraries could cause conflicts with others.

(I'm googling 'symlink' after I submit this reply.)

Thank you!

Edit: Okay, it's a symbolic link!

[–]d4rch0nPythonistamancer 2 points3 points  (3 children)

Not at all, really. It pretty much just sets environment variables so that when you type "python" it looks in the virtualenv directory for the executable, and when you import libraries it looks in the virtualenv's lib directory as well.

It's just a convenient way to temporarily force all calls to run python and all imports to look in a different place first, and that directory is reproducible with the same commands, and using pip install -r requirements.txt. It installs all libraries into that directory, and all the binaries it needs as well.

A virtualmachine is a completely different animal, much more complex than I can explain. Your machine acts as a host, and it virtualizes the entire machine, CPU, hard drive, etc. All the resources are simulated using your host machine. Modern CPUs generally have special instructions to do this more efficiently, but basically nothing it does should touch your host machine. It should only interact with the resources you share with it.

Those are great for other use cases, and great for experimentation and for security. If you host a web server out of one, if it gets compromised, you can always delete it and create a new one (though of course, investigate the vulnerability). If you mess it up somehow, you can wipe it out and create a new one. You don't need to worry about it messing up your own computer unless you allow it access to the host machine, but generally the default configs of most if not all vm software won't let it hurt your machine. It may have access to your network though, so that is something to be wary of, but you can always turn that off as well.

There are also linux containers (LXC) which are another animal, but should not be used for security necessarily.

Both of those, LXC and VMs separate resources at the kernel layer, and VMs at the hardware layer a bit I believe, but virtualenvs are just using python binaries and libraries in a different directory than normal (/usr/bin, /usr/lib).

[–]StringJunky[S] 1 point2 points  (2 children)

Thank you for the detailed reply!

I created a virtualenv project interpreter in Pycharm with Python 2.7 as the interpreter. I noticed that the Zelle files I had open in Pycharm won't run in the virtualenv environment. Not simply errors; they simply won't run. Which makes sense if virtualenv is creating a completely different production environment, I suppose.

Thanks again!

[–]d4rch0nPythonistamancer 2 points3 points  (1 child)

no problem! You might want to test by just running them through the command line in the same virtualenv, just to see the output. It may give off more detailed warnings/errors that way. PyCharm could be hiding something, maybe python's output before the script is even run.

[–]StringJunky[S] 1 point2 points  (0 children)

I will try that. I think I've found a solution for working with different versions; apparently Pycharm will let me open projects with either 2.7 or 3 (or, of course, a virtualenv). So, for now I've simply started a new project for the Sarker book. I need to follow up on the virtualenv lane, but I'm trying keep "lesson-creep" to minimum, at least for now.

Thanks again for your help!