I'm following a tutorial on Django and I'm suppose to create a folder in Ubuntu in terminal
$ django-admin startproject mysite
This above line shows
"Cannot find installed version of python-django or python3-django."
After installing all the required stuffs.
The recommended way of starting a django project in Ubuntu is using a virtualenv so first install it.
Then run
virtualenv -p python3 env
This will create an env named folder. Active the virtualenv by running
source ./env/bin/activate
Then install django with pip. now django will be installed in activated virtualenv
pip install django
and then create your project
django-admin startproject mysite
Related
I am having issues with virtualenv installations on a mac.
First change to the directory and activate virtualenv
cd my-project/
virtualenv venv
source venv/bin/activate
Second...my terminal changes to the virtualenv and install Django version 3.1.7
(venv) andrescamino#Robertos-MacBook-Pro WJKTM % pip install Django==3.1.7
To make sure the installation is on the virtualenv i make a pip freeze and these are the results
(venv) andrescamino#Robertos-MacBook-Pro WJKTM % pip freeze
asgiref==3.3.1
Django==3.1.7
pytz==2021.1
sqlparse==0.4.1
Then I start the project
(venv) andrescamino#Robertos-MacBook-Pro WJKTM % django-admin startproject bandsite
However when I go to the editor and check the settings file...it still shows the version installed globally which is the 3.1.2
Generated by 'django-admin startproject' using Django 3.1.2.
Am i missing something?
That's because vscode is using your global python installation. You can see and change which python environement vscode uses from the status bar in the bottom.
i want to develop django rest API in windows.
Due to some reason i have to use miniconda in my system.
My project location is c:/users/noman/dev/cardionic/ .
i create virtualenv 'env' using miniconda which is created in c:/user/noman/miniconda3/envs/env instead of base folder. I activate my env using 'activate env' and install django. I create new django project using 'django-admin startproject cardio' .
when i run 'python manage.py runserver' it generates "ModuleNotFoundError: No module named 'sqlparse' "
i have done my best but could not resolve this issue. Thanks in advance
First, Setup an environment
conda create — name django2 python>3.7
Switch to / Activate the environment
conda activate django2
Install Django — the default version was 2.2.1
conda install -v django
Encountered ModuleNotFoundError: No module named ‘sqlparse’ when running python manage.py runserver. This will resolved by conda install sqlparse.
i use vscode on windows10. I just created a Django project+app like this:
In the vscode powershell terminal:
python -m venv venv #createing a virtual environment called venv
.\scripts\activate #activate the virtual environment
pip install django==2.1.1 #install the newest version of Django
python -m pip install --upgrade pip #upgrading pip
pip install requests #install requests for api-requests
django-admin startproject api_order . #creates a django project called api_order
python manage.py migrate #create database
python manage.py runserver #starting the server
because of the server running in my powershell terminal i take a second powershell terminal and continue with activating the venv and creating a app.
.\scripts\activate
python manage.py startapp api_order_app #creating a app called api_order_app
When i now open the models.py python is reporting an problem "E0401:Unable to import 'django.db'" Same for all other imports in every other script.
What did go wrong?
I did this twice always the same problem.
This is how it looks like in the IDE
<img src="https://i.stack.imgur.com/JTmvb.jpg">
Thanks in Advance for helping me out.
Ben
I figured it out... I wasnt on the right virtualenvironment. But Django was only installed at the venv.
In Visual Studio Code you can choose the environment u want to use in the bottom left corner.
Now everything works just fine.
I have created a conda environment by typing the following conda create --name testenv python command from here.
Now one of my tutorials tells me to install Django which I happily did in the environment(That is the point of using environments right?, keeping dependencies straight) using pip3 install django.Post which I was told to do this django-admin startproject mysite Which didn't work. I am thinking because he was doing it in venv and I am in conda probably that's why(There is no venv folder in my test-app folder as well. Also I have already activated the environment). Every time I type the command django-admin startapp mysite I get this error.
Traceback (most recent call last):
File "/usr/bin/django-admin", line 18, in <module>
from django.core import management
ImportError: No module named 'django'
How do I fix this? I have already installed Django. What more am I supposed to do?
This question is old, but if anyone is wondering the exact steps to create a Django application using conda, here it is
conda create -n <nameoftheapplication> python=3.6
source activate <nameoftheapplication> Note: For Windows just put activate
pip install django
django-admin.py startproject <nameoftheapplication>
cd <nameoftheapplication>
ls
You should see manage.py and a folder called <nameoftheapplication> which contains settings files.
Firstly, open the anaconda prompt in windows then go to the project directory and enter the following command:
conda create -n python=3.6 anaconda
activate
pip install django
django-admin.py startproject
cd
python manage.py runserver
Then open web browser and enter the http://127.0.0.1:8000/ to see django page.
I am new in web programming, so just starting with Python and Django.
I am working on Windows 7 and already have Python 2.7 and Django 1.6.5 for a project I am working on.
For another project I need a virtual environment with Python 3.4 and Django 1.7 so I did:
install Python 3.4 in another folder (c:\python34)
create a folder for my new project (my_proj) and here executed:
> c:\python34\python -m venv py34env
> py34env/bin/activate
> django-admin.py startproject --template='my proj github archive' env my_proj
> cd my_proj
> pip install -r requirements.txt
> cd src
> python manage.py migrate
The file requirements.txt contains among other packages Django 1.7
Now command manage.py migrate gives an error: it seems it doesn't find Django.
If I do django --version I get no result, but if I do pip freeze it shows me Django 1.7.
Any help will be apreciated,
Thanks a lot,
Dani
When working with Python on Windows, I always install virtualenvwrapper-win: https://github.com/davidmarble/virtualenvwrapper-win to get all the same convenience commands that you have on Linux or OS X.
You can create a virutalenv for Python 3.4, or any other Python runtime using the -p option (short for --python) and specifying the path to the Python executable:
mkvirtualenv my_env -p C:\python34\python.exe