Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Django not working after moving directory.

Do I
have a path/Python installation issue?
Asked 3 years ago Active 1 year, 10 months ago Viewed 912 times

Background: I installed Python 3.5.2 on my Mac (which already contained 2.7.10)


and have been apparently running the two installations side-by-side without any
2 apparent issues. Everything works fine until I move the project folder somewhere
else, and then when I try to do anything I get the following error:

Traceback (most recent call last):


File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named django.core.management

My normal setup workflow is as follows:

• Install a virtual environment in the directory containing the Django project folder
(not the directory containing manage.py - one level up from that) with python3 -m
venv <venv-name>

• Activate the virtual environment and install Django, Pillow, whatever I need for
the project.

I know I'm missing something because I thought the way virtual environments
worked was that you installed them locally and then as long as all of that
accompanied your project folder, everything would be a-okay. But everything stops
working when I move the directory, and if I move it back it works again.

Can anyone tell me what kind of issue I'm dealing with here based on this? Is this
just normal behavior and I just need to get used to not moving Django project
folders?

UPDATE: If I delete the virtual environment folder and re-install it once the folder is
in the new location everything seems to work fine. I guess it's some issue with the
creation of virtual environments and some kind of link to my Python installation? I
have no idea.

python django

edited Nov 10 '17 at 20:54 asked Nov 10 '17 at 20:20


user6806370
By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy
Policy, and our Terms of Service.
Did you move the venv folder together with your project folder? – Juergen Nov 10 '17 at
20:35

@Juergen - Yes, e.g. I'll have Projects/my_project/my_project, where the contents of the
first my_project are only the virtualenv and my_project (which contains manage.py). So
I'm just moving the whole folder from Projects/ – user6806370 Nov 10 '17 at 20:39

@Juergen So I thought I was onto something because I copy-pasted another project


folder to another location and everything was fine, but then I tried deleting it from the
original location and now it's not working. So there must be some link between my
virtualenv and my Python installation? What could it be? – user6806370 Nov 10 '17 at
20:43

2 Answers Active Oldest Votes

Blind guess:

1 1) Did you activate your Virtual Environment? It sounds like manage.py couldn't find
the django installation.

2) Has the Environment Django installed?

3) Do you move the env itself? The generated activate -script has hardcoded (
mine: e.g. VIRTUAL_ENV="/home/thomas/Intevation/env" ) paths in it. I would
recommend to make a new env and install it there.

I encourage people to use: Pipenv

The traceback is a clear indicator, that wherever manage.py looks, is no django


installed.

edited Nov 10 '17 at 21:01 answered Nov 10 '17 at 20:51


Thomas Junk
5,250 2 25 39

1 1) Haha, yes -- unfortunately I made that mistake earlier on but fortunately caught myself
before coming here for help. 2) Yes, the only two packages I install for this particular
project are django and Pillow – user6806370 Nov 10 '17 at 20:52

Okay the hard-coded paths in the activate script makes sense. Thanks very much! I'll
take a look at Pipenv! – user6806370 Nov 10 '17 at 21:08

Late response, but I want to apport my workaround for this issue. Thanks to the
Thomas response I understood the problem by looking at the activate script. So,
By 1
using our
wassite, you acknowledge
easier that youthe
in my case restore have read and
original understand
path ourthese
and follow Cookiesteps:
Policy, Privacy

Policy, and our Terms of Service.
 
1. Before to move the project and with the virtual environment activated

pip freeze > requirements.txt

2. Then deactivate the environment and remove it

deactivate
rm -rf .env

3. Move the project to the desired directory

4. Generate a fresh new virtual env and activate it

python3 -m venv .env


source .env/bin/activate

5. Install the dependencies

pip install -r requirements.txt

answered Jan 1 '19 at 16:11


Max Cruz
348 3 9

By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy
Policy, and our Terms of Service.

You might also like