Django install & virtual environment

Hello,

New member here and a new Django user. I’m trying to learn Django and installed it last week while doing an online tutorial. I can’t find the tutorial I used and am curious about the Django install I did. I’ve been reading about installing Django in a virtual environment and am not sure if that’s what I did. is it possible to install it globally (correct term?)? How do I find out which way I installed it? Thanks.

I am also new, but as far as I know in the root folder of your Django project you should have a directory like “venv” (or whatever the name of your virtual environment is). Then you should be able to activate your virtual environment with source venv/bin/activate (and deactivate it by simply type in deactivate). You also can install it “globally” but with a virtual environment you are more flexible.

Item the first: Yes, it is possible to install Django and other dependencies globally to each version of the Python interpreter you have installed. There are ramifications for that, especially since many of us work on more than one project with (possibly) different versions of dependencies. That is the problem that virtual enviroments are designed to solve: To keep each projects dependencies separate.

Item the first, subitem A: Also, some operating systems use Python to run system commands. Installing different versions of packages into system Python can have…consequences.

Item the second: An easy way to find out if a package is installed in an enviroment is to open the shell and use the ‘python -m pip freeze’ command, where python is the command used to invoke the python interpreter you want. Whatever is installed will show up there.

Hope this helps!

-Jorge

1 Like

To add to the confusion, there are different ways to create a virtual environment. ralfzosel described how things work when using the venv module. It’s also possible that you used ‘pipenv’, where things work a bit differently.

Do you know what folder you were working in when you were following along with the tutorial you mention? If you don’t know at all what directory it was, you can do a normal file search (e. g. in File Explorer on Windows) on your computer for manage.py. Every Django project created has a file named that. Once you find where the manage.py file is located, go to its folder using your file explorer or your terminal/bash/console/command line interface. Look at what other files you have there. If you find a directory called ‘venv’, as ralfsozel says, or a ‘Pipfile’ file, then you used a virtual environment. If you only see a ‘manage.py’ file and a ‘db.sqlite3’ file, other than a directory named according to the project you created when doing the tutorial, you probably didn’t use a virtual environment.

You can also open up your command line interface and write the command django-admin help. If you see a lot of info about different commands and a message about ‘Note that only Django core commands are listed’, then you installed django without using a virtual environment (unless you installed it first with and then without a virtual environment, or vice versa). If you see an error message about how the command isn’t recognized, you installed django within a virtual environment.

Hope this helps. Good luck!