0

I've been trying to execute django-admin from within a LiClipse project using:

projectName = "someProject"
command = 'django-admin startproject ' + projectName
process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)

and also

subprocess.check_call(shlex.split(command))

But each time I get the error:

FileNotFoundError: [Errno 2] No such file or directory: 'django-admin'

However, when I run the same program from the Linux terminal using python3 main.py, it works fine.

So I figured it might be because django-admin's path isn't added to PYTHONPATH. I did a locate "django-admin" to find these paths:

/home/nav/.pyenv/shims/django-admin
/home/nav/.pyenv/shims/django-admin.py
/home/nav/.pyenv/versions/3.8.7/bin/django-admin
/home/nav/.pyenv/versions/3.8.7/bin/django-admin.py
/home/nav/.pyenv/versions/3.8.7/bin/__pycache__/django-admin.cpython-38.pyc
/home/nav/.pyenv/versions/3.8.7/lib/python3.8/site-packages/django/bin/django-admin.py
/home/nav/.pyenv/versions/3.8.7/lib/python3.8/site-packages/django/bin/__pycache__/django-admin.cpython-38.pyc

and added it to PYTHONPATH... enter image description here

...but I get the same error when I run the program from within LiClipse.

Does anyone know why this problem is happening and how it can be fixed?

9
  • Well, you added an interpreter, but not something to your shell PATH. Normally this is handled by the virtualenv's "activate" command and IDE's have support for virtual environments. If Eclipse doesn't have that, it means you're going to have provide absolute paths to the django-admin command you want executed or you properly setup pyenv so that Eclipse doesn't need additional configuration. The shims are already there. Commented Apr 25, 2021 at 13:06
  • Tried adding export PATH="/home/nav/.pyenv/versions/3.8.7/bin/:$PATH" to ~/.bashrc. Restarted computer. Am getting the same FileNotFoundError: [Errno 2] No such file or directory: 'django-admin' error. Commented Apr 25, 2021 at 16:30
  • Does that work in your shell now? Then Eclipse must somewhere be using a sanitized / hardcoded path. Unfortunately, I'm not familiar with the Eclipse itself. If it doesn't work in your shell either, then either you're not using bash as a shell or somewhere later in the bash startup chain, PATH is overridden again. Commented Apr 25, 2021 at 17:05
  • I had already mentioned that the program works fine when I run it from the shell using python3 main.py Commented Apr 26, 2021 at 5:01
  • Then print(os.environ['PATH']) before invoking subprocess. Compare the difference when invoked from Eclipse versus the command line. Commented Apr 26, 2021 at 16:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.