pip3 is installing django globally not inside my environment - django

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!!!

Related

Do I need to use virtual environment while using docker?

I didn't know what is the benefit of Docker over virtual environment. Is it necessary to use virtual environment and docker at the same time.
Before today, Basically I used virtual environment to crate Django project. But today My friend recommended me to use docker. I'm confused what should i use ?
I used this command to create virtual environment
python3 -m venv virtual_environment_name
Is this is best way to create virtual environment or should i use another way to create virtual environment
I would rather use pipenv to replace virtualenv at local development environment, and docker without virtual environment at production. Here is my Dockerfile(run django with gunicorn):
FROM python:3.6
ENV PYTHONUNBUFFERED 1
# switch system download source
RUN python -c "s='mirrors.163.com';import re;from pathlib import Path;p=Path('/etc/apt/sources.list');p.write_text(re.sub(r'(deb|security)\.debian\.org', s, p.read_text()))"
RUN apt-get update
# aliyun source for pip
RUN python -c "s='mirrors.aliyun.com';from pathlib import Path;p=Path.home()/'.pip';p.mkdir();(p/'pip.conf').write_text(f'[global]\nindex-url=https://{s}/pypi/simple\n[install]\ntrusted-host={s}\n')"
# Optional: install and conf vim, install ipython
RUN apt-get install -y vim
RUN wget https://raw.githubusercontent.com/waketzheng/carstino/master/.vimrc
RUN pip install ipython
# copy source code to docker image
WORKDIR /carrot
ADD . .
# required packages for carrot
RUN apt-get install -y ruby-sass
# install gunicorn and Pipfile
RUN pip install pipenv gunicorn
RUN pipenv install --system
RUN python manage.py collectstatic --noinput
# database name and rpc server ip
ENV POSTGRES_HOST=db
ENV RPC_SERVER_IP=172.21.0.2
EXPOSE 9000
# the PASSWORD env should be replace to a real one
CMD ["gunicorn", "--bind", ":9000", "--env", "PASSWORD=123456", "--error-logfile", "gunicorn.error", "--log-file", "gunicorn.log", "carrot.wsgi:application"]

I installed Django version over 2.x but the command django-admin startproject(lowercase) make project with 1.x version

python3 -m venv venv
source venv/bin/actvaite # activate virtual env
pip install --upgrade pip
pip3 install Django # Django 2.1.7 installed
django-admin startproject temp # 1.x version
Django-admin startproject temp # 2.x version
django-admin vs Django-admin
django-admin start with lowercase make project 1.x version
Django-admin start with uppercase make project 2.x version
offical docs - start with lowercase
docs
summary
1) whats wrong in my environment?
2) how can i make project with django-admin(lowercase)
It seems like the pip command is pointing to Python 2.x, and pip3 is pointing to Python 3.x. To see if this is this case:
deactivate # in case you're in a virtual environment
pip --verison
pip3 --verison
This will show you which version of Python each one points to. Since Django 2.x is only compatible with Python 3, pip will automatically installed Django 1.11.x if you're installing with pip under Python 2.x.
The best way around this is to ensure you're using a virtual environment. To start a new Django project:
python3 -m venv my_project_venv
. my_project_venv/bin/activate
pip --version # Make sure it is pointing to Python 3
pip install django
django-admin startproject my_project
The next time you come back to work on your project, you can re-activate the virtual environment with everything you've pip installed inside it:
. my_project_venv/bin/activate
Good luck!
Did you install Django in your environment?
pip install Django
A quick workaround is running the following in your environment:
python3 venv/bin/django-admin startproject temp

django installation not working virtualenv

I have installed virtualenv
pip3 install virtualenv
create a virtualenv
virtualenv djangoenv
access the virtualenv
source ./djangoenv/bin/activate
Then I install
pip3 install django
when import django I get errorno module named django
django-admin.py --version displalys 1.9.4 So it is installed. what am I doing wrong ??
Install virtualenv with pip :
sudo pip install virtualenv
create Virtualenv
virtualenv -p /usr/local/bin/python3 virtualenv_name
activte Virtualenv
source virtualenv_name/bin/activate
finally install django
pip install django
With that you will get django installed using python3

Django not installed in venv?

Would anyone know possible reasons why Django is being installed in the global site package and not my venv's site package folder?
Here's my set up and what I did, this is a bit detailed since I'm new to Python/Django and not sure which information is important:
Python 3.3 is installed in c:\python33
I have virtualenv, pip, easy_install installed in C:\Python33\Scripts.
My venv is c:\users\username\projects\projB
This venv was created using pyvenv, not virtualenv.
I activated the venv.
I changed directory to C:\Python33\Scripts to run "pip install django".
Django was created inside C:\Python33\Lib\site-packages and not inside C:\users\username\projects\projB\Lib\site-packages.
Do I need to install pip inside my venv and use that to install Django?
You can specify in your virutalenv wich python version you whant:
$ virtualenv -p <PATH TO PYTHON VERSION> my_virtualenv
Then:
$ source my_virtualenv/bin/activate
$ pip install Django==1.5.2
This will install the good version of django in your virtualenv according to your python version.
Thanks to virtualanv, you will be able to save/freeze and install your environement on another machine:
$ pip freeze > requirement.txt
$ pip install -r requirement.txt
You will see in the requirement.txt file the django dependency.
Pip should be installed when you create the virtual environment. Don't change directory into C:\Python33\Scripts before running pip. It looks like that means you use the base install's pip instead of your virtual environment's pip.
You should be able to run pip from any other directory. However I'm not familiar with python on Windows, so I'm not certain that pip is added to the path when you activate the environment. If that doesn't work, you'll have to change directory into the bin directory of your virtual environment, then run pip.
What happened to me was that I was trying to install django from outside the environment directory/folder.
So make sure you are inside the environment directory and then use pip install django

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.