I am just starting out on using the django framework. One thing that bugs me is the django-admin utility. Is it part of the python installation or is it part of the django installation through pip?
The way I've been doing my projects is
Make a virtual Environment.
Create a django project in the environment through django-admin.
and then I just install the django framework using pip inside the environment.
My question arises because inside the virtual environment, I used django-admin to create the project before installing the framework.
https://docs.djangoproject.com/en/2.1/ref/django-admin/
django-admin is Django’s command-line utility for administrative
tasks.
django-admin utility comes with any Django installation. inorder to use django-admin command, the django-admin script should be on your system path if you installed Django via its setup.py utility. If it’s not on your path, you can find it in site-packages/django/bin within your Python installation.
use the link given above to find the instructions for windows as well as linux.
and to answer your question, django-admin is a part of django framework
I have ran into something similar. Where in a virtual enviroment I create for python 3 used my global python 2 installation. Try creating a new virtual environment just like before, and this time try using "python django-admin" instead of just "django-admin". A question for you, is this a Windows environment, I ask because that is the only environment I have witnessed this behavior in. I believe by using "python django-admin" it will force it to use the virtualenv's sandboxed python.
Related
I'm been using VS code and venv for my Django projects and have been able to debug using the tutorial provided by Microsoft here.
https://code.visualstudio.com/docs/python/tutorial-django
However, I have now switched to pipenv instead which I activate using the commmand pipenv shell.
When I now run using the Django debug configuration I get an error.
Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable?
Did you forget to activate a virtual environment?
I can't find any resources to guide me on this.
Do I need to change the launch.json file to make it work with pipenv?
you just need to choose an interpreter
in my case, all pipenv interpreters are located in the ~/.virtualenvs folder
here is the screenshot
Bottom Line:
I can get everything to work by configuring two separate virtual environments, one for pyCharm and one for the CLI. Is this really necessary or should I be able to use 1 virtual environment for both as I expected?
More Detailed explanation:
I'm very new so this is probably a facepalm type of question so i'll try to be terse.
I'm using Linux Mint, Python 3.6, django 3.0.3, and pyCharm 2019.3.1.
I can create a virtual env using venv in the cli and it works.
I can also create a NEW virtual env in pyCharm through the settings: Project: Interpreter interface, and it works, however it doesn't have venv as an option, it only has virtualenv.
But if I try to activate the virtual env i created in pyCharm from the cli (using virtualenv of course, not venv), it fails hard and thinks i'm using python 2.7 which isn't even installed on my system. If it try to point pyCharm at the virtual env I setup on the cli, I get an error 134.
Is this just a known/expected issue? Must I have two virtual environments for every project I want to access via both pyCharm AND the cli? And I assume this is unrelated but I also find it odd that pyCharm lists my interpreter as python 3.7, which also is not installed on my system. I'm using 3.6 alone.
Thanks for your time.
At this time, I'm going to just answer this as: you need a separate virtual env for each (pyCharm and CLI) as this approach is not difficult or time-consuming and I have not had any issues working in this way.
I started learning django a few days back and started a project, by luck the project made is good and I'm thinking to deploy it. However I didn't initiate it in virtual environment. have made a virtual environment now and want to move project to that. I want to know how can I do that ? I have created requirements.txt whoever it has included all the irrelevant library names. How can I get rid of them and have only that are required for the project.
Django is completely unrelated to the environment you run it on.
The environment represents which python version are you using (2,3...) and the libraries installed.
To answer your question, the only thing you need to do is run your manage.py commands from the python executable in the new virtual environment. Of course install all of the necessary libraries in the new environment if you haven't already did so.
It might be a problem if you created a python3 environment while the one you created was in python2, but at that point it's a code portability issue.
I'm currently hosting with a dreamhost shared VPS. I do not have sudo rights. I want to install django packages but I cannot to /usr/local/lib/python2.7/dist-packages/ because python is root access only. I have setup a directory in my user directory also called dist-packages to which I have copied all my packages to. I want to use the packages in the dist-packages directory I created to build my django app. Is possible to use my packages? I'm looking for a work around. I do have virtual python env installed, is there a way to use it maybe?
Python 2.7
Django 1.9
My current setup
/home/myuser/mydomain.com/
env/
myApp/
passenger_wsgi.py
public/
How do I setup the env?
You should be using virtualenv for sure(I'm surprised that you are still looking for a work around). It's really inconvenient to use default python for everything. virtualenv will create an isolated python directory of your choice and install everything in there. When you want to use it, just "activate" it then you are automagically in that python environment.
It's almost trivial to learn how to create one, you can even create as many as you like, each with different packages installed. Check their doc for more details.
I'm working on a Django project in VS 2015 Community with PTVS, which has been very useful for a free tool. I recently realized that I should be using virtual environments during development, and found out that Python 3 includes this feature by default, and PTVS 2.0+ supports it- cool!
I created a couple environments as an experiment, and in one I installed the celery[redis] bundle since I'm trying to figure out how to implement a background task. I was having trouble getting the basic celery tutorial task to work, so I decided to remove the environment from my Django project, deactivate it, and start over.
However, once I removed it via PTVS and ran deactivate from the command line inside the environment directory, I could still run celery commands from my top-level project directory. I've never installed celery globally- only to my test environment via the Python Environments menu in PTVS.
Why is this? Am I thinking of virtual environments as too similar to truly discrete environments such as containers? My impression from reading PTVS venv documentation is that if a package is present in a virtual environment which is then deactivated, I shouldn't be able to use it in other environments (or globally). I thought it might be an issue with my Windows PATH, but I didn't see anything related to Python or celery.
Apologies if this is a duplicate- it's been difficult to find questions on the PTVS implementation of venv rather than Python + virtualenv in general.