Django import error when copied project to laptop

Hi,

I wonder if anyone could help please.

I have built a django project (basic web project) on pi zero, all works well.

It’s in a base directory called web, which is in in an virtual environment called (w_env)

I have copied the whole project (web) on it on to my laptop with same structure onto the c drive.

Laptop has windows Linux wsl. (Ubuntu)

I type cd /mnt/c/web

And then source w_env/bin/activate

(w_env)web etc etc

All works well just as I’m on if on raspberry pi zero, same directory structure etc.

installed pipx Django, all good

Tested/checked Django version in both web directory and web/web directory and it prints Django version 6 in both.

All works well and Django appears to be installed in the virtual environment (w_env).

But when I try to run the server from (w_env)web python3 manage.py runserver

(web being the base directory)

Returns an Error from manage.py file

It says it can not find the installed Django module, is it installed? Have you activated virtual environment? Is path correct in settings.py?

Any ideas what the path should be in settings.py assuming this is the cause of the problem?

Current path in settings.py (generated Django code on raspberry pi)

From pathlab import Path

BASE_DIR = Path(_file_).resolve().parent.parent

Maybe it is not possible to copy a complete web Django project and use it on a different machine?

Thanks Steve

It appears Django is installed here?

/home/pi/.local/share/pipx/venus/django

using wsl and Ubuntu.

settings file can not import Django.

Maybe it is called django-admin?

No, there’s some other issue here.

For the moment, forget about anything you’ve done on the Pi, let’s focus only on your wsl environment.

Please show the complete and full directory name where the project resides. Also identify the directory in which your settings.py file resides.

Show the full directory name for the virtual environment.

Finally, post the complete contents of your manage.py file.

Copying your project is generally ok.

Copying virtual environments is not. You should create the virtual environment for a project on the machine in which it’s being run.

Thanks Ken,

Manage.py and settings.py in nano

windows root -can see Django.

Dir’s shown on linux and the (w_env) and how I activate the virtual environment.

(Only one photo per post allowed)

Windows showing Ubuntu dir.

Settings.py

Manage.py

Thank you for trying to be comprehensive here, but please do not post images of code, configurations, or other terminal-based text output.

Copy/paste the text into the body of your post between lines of three
backtick - ` characters. This means you’ll have a line of ```, then your code,
then another line of ```. This forces the forum software to keep your code
properly formatted.

For example, a directory listing might look like this:

(d52) tskww@MSI:~/git/mysite$ ls
manage.py*  mysite/  polls/  polls.sqlite3  requirements.txt  test.sqlite3

Anyway, to try and answer my questions from what you posted:

Project: /mnt/c/web
Settings.py: /mnt/c/web/web

Please show the output of a which python3 command.
(On my system it looks like this:)

(d52) tskww@MSI:~/git/mysite$ which python3
/home/tskww/ve/d52/bin/python3

Virtual environment: /mnt/c/web/w_env

It’s this last one that concerns me. After copying your project from the Pi to this system, did you completely rebuild your virtual environment? You should delete this directory and recreate it (and its contents) completely.

ok thanks - here are the answers


/mnt/c/web/bin/python3

location of virtual enviroment

/mnt/web/w_env

so from /mnt/web
i re-installed python3, and / virtualenv and (django again)

then ran virtualenv w_env and it appeared to re create a virtual environemt in wsl.

settings.py location is

/mnt/web/web/settings.py

Side note: You need to use the backtick - `, not the apostophe ' or any other type of “smart quote”. When marking off multiple lines, the lines of three backticks ( ``` ) must be lines by themselves and not part of other lines. When marking text on one line, use one backtick before and after the text. (I edited your post to correct the formatting.)

This is not the python in your virtual environment. After activating the virtual environment - if it’s /mnt/web/w_env (did you mean /mnt/c/web/w_env?), which should show you /mnt/web/w_env/bin/python3.

Again, did you mean /mnt/c/web/web/settings.py?

How? (Please list the specific commands run to do this. I don’t need to see all the output, just the commands used.)

Hi

My mistake

Yes my mistake it is

```pi@kim:/mnt/c/web/w_env/$ which python3```

pi@kim:/mnt/c/web/w_env//bin/python3```

Yes an you are correct with settings.py.

pi@kim:/mnt/c/web/web/settings.py```



My re installations

In pi@kim:/mnt/c/web

``Install python3 `` I can’t quite remember 100% but it appeared to work

and

install Django``` - - force```

Because it was already installed, had to force, and it installed.

And from the same directory as above

Virtualenv w_env2```

And it worked

So also thought better try and re write w_env

virtualenv w_env```

And it appeared to work

Then activated it, and it appears to work, but Cant import Django module.

I’m not familiar with pipx, and some of its limitations shown at Comparison to Other Tools - pipx concern me a little when it comes to Django.

Try creating your virtual environment with venv and installing your packages using pip instead of pipx.
e.g.

python3 -m venv /mnt/c/web/w_env
. /mnt/c/web/w_venv/bin/activate
pip install --upgrade pip wheel setuptools
pip install Django

After this, a pip list should show something like this:

Package    Version
---------- -------
asgiref    3.11.1
Django     6.0.2
packaging  26.0
pip        26.0
setuptools 80.10.2
sqlparse   0.5.5
wheel      0.46.3

Side note: And again a reminder. When marking blocks of text, use ``` alone on lines before and after the text being marked, not on the same line as any other text.

When marking text on a single line of text, use one ` at the beginning and end of the text. (Must all be on the same line)

Wow it worked! Huge Thanks!

I had to install bootstrap 5

pip install Django_bootstrap-v5

This installed ok but then changed Django version from 6.02 to 4.28

Still bootstrap5 did not tally with web project html pages

pip install django_bootstrap5

Which now works with web project html pages etc. same as pi zero, works the same.

Thanks.