shell script for django VE causing deactivation of VE - django

So I am trying this simple script which is essentially this (a full gist can be found here):
#!/bin/bash
virtualenv env
source ./env/bin/activate
pip install --upgrade pip
pip install django
pip freeze > requirements.txt
django-admin startproject mysite .
git init
git config user.name "somename"
git config user.email "some-email#somedomain.com"
gitIgnore="
env/
*.pyc
"
echo '$gitIgnore' > .gitignore
git add .
git commit -a -m 'Initial commit'
After running the script I see that I am no longer within the virtual environment. Not sure why that is. I didn't deactivate at any point, so I would expect that I would still be in the env virtualenvironment.
Anyone can please shed some light on why my virtual environment is getting deactivated?

Related

Django Tutorial - install the previously cloned copy of Django

I was following this tutorial when this error occurred. I would appreciate it if anyone could tell me what is going wrong here.
https://docs.djangoproject.com/en/3.0/intro/contributing/
(djangodev) (base) XXXX#XXXX-MacBook-Air hello_django % python -m pip
install -e /path/to/your/local/clone/django/
ERROR: /path/to/your/local/clone/django/ is not a valid editable requirement. It should either be a path to a local project or a VCS URL (beginning with svn+, git+, hg+, or bzr+).
This occurred after entering the following code
% git clone https://github.com/XXX/django.git
$ python3 -m venv ~/.virtualenvs/djangodev
$ source source ~/.virtualenvs/djangodev/bin/activate
~/.virtualenvs/djangodev/bin/activate
python -m pip install -e /path/to/your/local/clone/django/
The last command should be as executed as follows (After you are in the directory from where you did the clone command)
python -m pip install -e django

pip3 is installing django globally not inside my environment

I used virtualenvwrapper to create a new env but when I tried to install pip3 to install newer versions of django it was install globally although my environment was activated , which leads to global installation of django ..
How can I use it only inside my virtual env
did you activated virtual env first ? If you see env name in front of name in terminal - it is activated. If it is activated try python3 -m pip install --upgrade pip
then python3 -m pip install django
it is obliged to install last stable version of django (3rd for now) I'm doing this often
Use below commands to install django inside virtual environment.
1) upgrade pip3:
python3 -m pip install --upgrade pip
2) Install virtual env
pip3 install virtualenv
3) You can then create a virtualenv using the full path like this:
virtualenv -p /home/example_username/opt/python-3.6.2/bin/python3 venv
4) Activate virtual env
source venv/bin/activate
5) install Django
pip3 install Django
1.create a virtualenvironment with virtualenv or venv.
2.Activate the virtual environment by entering in the virtual environment folder and type this command if you are on windows cd scripts then type activate.bat or if you are using git bash just do . scripts/activate then you will see ("name of your virtual environment") which proves that your virtual environment is active.
3.Then you can pip install django in your virtual environment
some images below to guide you
enter image description here
enter image description here
you are welcomed!!!

Django installation on Mac

I'm trying to install Django on Mac, Python version 3.7 already installed , here is the comment I have put in terminal-
Django-admin startproject hello
command not found
pip install virtualenv ,
virtualenv some name inside the less than and greater than sign ,
and then cd into the directory and run:
,
source bin/activate,
pip install Django
hope this will help you.. :)
Follow the following steps to install and use django
Install django. $ python -m pip install --upgrade django
Now, check the installation $ python -m pip freeze | grep django
Create django project $ django-admin startproject mysite
What i see wrong in your question ? You are using Django-admin

Django 2.1.1 Import Errors

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.

How to install image processing just for a virtualenv project with pip for django

But I'm looking to install freetype, libjpeg, PIL build to add image processing to my django projects I've followed this installation http://dakrauth.com/blog/entry/python-and-django-setup-mac-os-x-leopard/ which installs it site wide but I can get it inside my virtualenv project.
Do I just cd into the working directory of the virtualenv (project) and install it there and will it just be available for that project or do I use pip? I couldn't find the packages in the pip repository. Can someone enlighten me please.
curl -O http://pypi.python.org/packages/source/d/distribute/distribute-0.6.21.tar.gz
tar -xzvf distribute-0.6.21.tar.gz
cd distribute-0.6.21
python distribute_setup.py
easy_install pip
pip install virtualenv
virtualenv --distribute --no-site-packages [myproject]
cd [myproject]
source bin/activate (this activates the sandbox that virtualenv created)
pip install django mysql-python
Go to the working directory of the virtualenv and then run
$ source bin/activate
This will set that virtual environment as your active one. So now that it's active, you can install what you want, either manually (by following those steps on the site you linked to) or with pip and it will automatically install it into your active virtualenv.
If you then, say, run python manage.py runserver while the same virtualenv is active, django will have access to your newly installed package. Once you want to unset that virtual environment as your active one, simply do deactivate.
I ran into something similar; what I did was install it into the default directory (e.g. Python27/Lib/site-packages) then cut and paste all the new files put there into the created environment's site-packages. Hacky, but works.
After that you can follow EEVIAC's instructions to actually get your server running.