[Linux Mint]

Linux Mint

I'm following a book on Django and it has this -> https://hellowebapp.com/setup/ accompanying website. Take a look below at what I'm getting when I get to the "Start your Django project" section of the link.

Here's a peak at my terminal input and feedback.

(venv) user@mothership myhellowebapp $ pip install Django==1.9.6
Collecting Django==1.9.6
Downloading Django-1.9.6-py2.py3-none-any.whl (6.6MB)
100% |████████████████████████████████| 6.6MB 138kB/s
Installing collected packages: Django
Successfully installed Django-1.9.6
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
(venv) user@mothership myhellowebapp $ git init
Initialized empty Git repository in /home/user/projects/python/django-projects/myhellowebapp/.git/
(venv) user@mothership myhellowebapp $ django-admin.py startproject hellowebapp .
django-admin.py: command not found
(venv) user@mothership myhellowebapp $ ls
venv
(venv) user@mothership myhellowebapp $ python django-admin.py startproject hellowebapp .
python: can't open file 'django-admin.py': [Errno 2] No such file or directory
(venv) user@mothership myhellowebapp $ ls

Note that I already have python 2.7 & 3.5 installed on my system and when referring to python my system is by default pointing to python 2.7. Any ideas?

Dani AI

Generated

Good troubleshooting and resolution by and — this usually isn’t a Django bug but a virtualenv / PATH issue. It’s possible to see the (venv) prompt yet still call the system Python if the shell cached the location of python or the PATH wasn’t updated as expected. Re-creating the environment in a fresh directory often fixes broken entry points, which matches ’s final post.

Quick checks to run (safe, won’t modify anything):

type -a python
python -V
python -c "import sys; print(sys.executable)"
python -m pip --version
echo $PATH

What to look for: the python executable printed by the python -c line should live inside your venv/bin directory. If it doesn’t, the activate script didn’t put venv/bin first on PATH, or your shell has a cached location for the python command. Run hash -r (bash) or start a new shell, then re-source the activate script. Use python -m pip ... rather than pip ... so you’re guaranteed to use the pip that belongs to that interpreter.

Suggested minimal, robust workflow for new environments:

python3 -m venv venv
. venv/bin/activate
python -m pip install --upgrade pip setuptools wheel

Notes and cautions: avoid using sudo or your system package manager to install packages into a virtualenv; those operate at the system level and can mask problems. If user-local installs (like ~/.local/bin) appear before venv/bin in your PATH, they can override your venv scripts — ensure venv/bin is first while activated. If the problem recurs despite these checks, inspect shell startup files for aliases or PATH edits and verify VIRTUAL_ENV is set when activated.

Recommended Answers

All 7 Replies

Try which pip and which python. Both should be in your virtual env's bin directory. django-admin.py should be in the same directory. You can also use locate django-admin.py to find all the files with that name in your file system.

I'm not completely sure how a venv works but I'm guessing the which python & which pip shouldn't be returning an absolute path from root the way they are below. I'm assuming that they should be displaying relative paths from the either the project directory or the venv directory but I don't know for sure

   user@mothership myhellowebapp $ source venv/bin/activate
    (venv) user@mothership myhellowebapp $ which python
    /usr/bin/python
    (venv) user@mothership myhellowebapp $ which pip
    /usr/bin/pip
    (venv) user@mothership myhellowebapp $ locate django-admin.py
    /home/user/.local/bin/django-admin.py
    /home/user/.local/bin/django-admin.pyc
    /home/user/.local/lib/python2.7/site-packages/django/bin/django-admin.py
    /home/user/.local/lib/python2.7/site-packages/django/bin/django-admin.pyc
    /home/user/.local/share/Trash/files/NewerFiles/orig/.local/share/Trash/expunged/3117399120/build/lib/django/bin/django-admin.py
    /home/user/.local/share/Trash/files/NewerFiles/orig/.local/share/Trash/expunged/3117399120/build/scripts-3.3/django-admin.py
    /home/user/.local/share/Trash/files/NewerFiles/orig/.local/share/Trash/expunged/3411875491/build/lib.linux-x86_64-2.7/django/bin/django-admin.py
    /home/user/.local/share/Trash/files/NewerFiles/orig/.local/share/Trash/expunged/3411875491/build/scripts-2.7/django-admin.py
    (venv) user@mothership myhellowebapp

I don't think I bothered to try and install python or pip to the virtual environment but thought I would just use my system wide python and pip for that and instead focust on just installing django localy to the venv. But even when I tried to install python and pip localy to the venv to see if that was the problem this is what I got.

(venv) user@mothership myhellowebapp $ sudo apt-get install python
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python is already the newest version (2.7.11-1).
0 upgraded, 0 newly installed, 0 to remove and 40 not upgraded.
(venv) user@mothership myhellowebapp $ sudo apt-get install python-pip
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python-pip is already the newest version (8.1.1-2ubuntu0.4).
0 upgraded, 0 newly installed, 0 to remove and 40 not upgraded.
(venv) user@mothership myhellowebapp $

This is strange, there should be a python interpreter in the virtualenv's bin/ directory. Didn't you create the virtualenv with a python interpreter such as in

virtualenv --python=python2.7 mydir

?

No, I just followed the instructions here -> https://hellowebapp.com/setup/
That site is paired with the Django book I'm reading. Should I have done it differently?

You should be using the python interpreter and the pip command from your venv bin/ directory. What's in your venv's bin directory ?

user@mothership myhellowebapp $ source venv/bin/activate
(venv) user@mothership myhellowebapp $ ls -l venv/bin
total 3508
-rw-r--r-- 1 user user    2125 Dec 20 22:35 activate
-rw-r--r-- 1 user user    1067 Dec 20 22:35 activate.csh
-rw-r--r-- 1 user user    2265 Dec 20 22:35 activate.fish
-rw-r--r-- 1 user user    1137 Dec 20 22:35 activate_this.py
-rwxr-xr-x 1 user user     295 Dec 20 22:35 easy_install
-rwxr-xr-x 1 user user     295 Dec 20 22:35 easy_install-2.7
-rwxr-xr-x 1 user user     267 Dec 20 22:35 pip
-rwxr-xr-x 1 user user     267 Dec 20 22:35 pip2
-rwxr-xr-x 1 user user     267 Dec 20 22:35 pip2.7
lrwxrwxrwx 1 user user       7 Dec 20 22:35 python -> python2
-rwxr-xr-x 1 user user 3546104 Dec 20 22:35 python2
lrwxrwxrwx 1 usr user       7 Dec 20 22:35 python2.7 -> python2
-rwxr-xr-x 1 user user    2384 Dec 20 22:35 python-config
-rwxr-xr-x 1 user user     274 Dec 20 22:35 wheel

I just followed the exact same steps from the website again only in a new directory and now everything is working fine. Go figure. Thanks Grib.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.