How to have django-admin recognized in Eclipse/LiClipse? - python

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...
...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?

Related

No such file or directory when running a python script in WSL

I'm trying to run a python script in WSL that runs Ubuntu.
In WSL, the following command does not work:
admin:/mnt/c/Users/admin$ /mnt/c/Users/admin/repo/env/Scripts/python.exe /mnt/c/Users/admin/repo/script.py
C:\Users\admin\AppData\Local\Programs\Python\Python38-32\python.exe: can't open file '/mnt/c/Users/admin/repo/script.py': [Errno 2] No such file or directory
However, the following individual commands work:
admin:/mnt/c/Users/admin$ /mnt/c/Users/admin/repo/env/Scripts/python.exe repo/script.py
admin:/mnt/c/Users/admin$ /mnt/c/Users/admin/repo/env/Scripts/python.exe
admin:/mnt/c/Users/admin$ cat /mnt/c/Users/admin/repo/script.py
Why am I seeing this strange behavior? How do I run a python script using absolute path?

No such file or directory on Mac terminal for python

hello.py is my first python program. It is saved on my desktop.
In the terminal I write in front of
user#AA-MacBook-Air ~ % python3 hello.py
The error is
can't open file 'hello.py': [Errno 2] No such file or directory
Kindly help me understand the problem and solve it.
In the terminal you are currently in the directory ~. This signifies the folder /Users/<username>. Your script is on your desktop.
Type cd Desktop to change to /Users/<username>/Desktop and then run python3 hello.py.
you first need to change destination with cd
The error message, No such file or directory pretty much gives the explanation. Check if the file hello.py is present in the correct working directory. This can done graphically or using the ls command. If it is not present, copy the file the to the directory or navigate to the location of the file hello.py in terminal using cd.

Error ' [Errno 2] No such file or directory' when trying to create a new Django project

I'm following a Udemy course on learning Python and I have got to a part about learning Django. I have created a folder on my desktop and tried to start a Django project in it using CMD, however when I try to start the project I get the error:
d:\python\python: can't open file '3.6\python.exe': [Errno 2] No such file or directory
I have tried finding solutions but since I've never really used CMD I have no idea what to do, please help!
I have tried searching up solutions but I've been unable to find others with the same problem. Here is what I typed in CMD:
C:\Users\Thomas>cd desktop
C:\Users\Thomas\Desktop>cd newsite
C:\Users\Thomas\Desktop\newsite>django-admin startproject mysite
d:\python\python: can't open file '3.6\python.exe': [Errno 2] No such file or directory
C:\Users\Thomas\Desktop\newsite>

Configuring the working directory in Eclipse 3.8.1 with PyDev-project

I'm trying run a python script in Eclipse 3.8.1 but I keep getting the error message:
IOError: [Errno 2] No such file or directory
The problem occurs in a code line:
train_labels = np.loadtxt("./examples/data/class_train.labels")
Here is a screenshot of my project:
It seems the relative path starts from the location of the script itself, whereas I would want the relative path start from the root directory of the project, that is the RLScore-folder as you can see in the image.
How do I configure this?
P.S. I wouldn't want to edit the code, because this is not my own code and I would need to do the editing into many other files in the distribution.
try :
train_labels = np.loadtxt("../data/class_train.labels")

can't create django project using Windows command prompt

if i run
django-admin.py startproject mysite
django-admin.py (which is located in C:\python27\scripts/django-admin.py) will open in a file editor (now it opens in python ide, but in the past i had pype so it would open in pype) so the file opens:
#!C:\Python27\python.exe
from django.core import management
if __name__ == "__main__":
management.execute_from_command_line()
i see no output in the command prompt at all, so lets say i typed
C:\abc:>django-admin.py startproject mysite
when I hit enter i see C:\abc>
and the project will not be created using the command prompt
this issue is not new for me, i'm creating my python projects using pydev, i would love to fix this issue with the command prompt though :)
#slugonamission
when I run
pyhon django-admin.py startproject mysite
the output of the command prompt is
python: can't open 'django-admin.py' file : [Errno 2] No such file or directory
I don't think Windows supports the shebang line. Try invoking it with python django-admin.py ...
I'm using python 2.7 , django 1.7 in windows7.
WAY-1:
1) Go to C:\Python27\Scripts (or your installation directory)
2) open cmd and enter python django-admin-script.py startproject ProjectName
3)Your project folder with all necessary files ll be created there.
The problem is in windows, django-admin.py is supplied as django-admin-script.py
WAY2:
1)Open cmd at any location you want.
2)enter django-admin startproject ProjectName
3)Your project folder with all necessary files ll be created there.
Its because the .exe file is supplied.
This often happens in Windows.
Open cmd at any location you want.
enter django-admin startproject ProjectName (don't add the .py extension to the admin)
Your project folder with all necessary files will be created there.
This is because the .exe file is supplied inside the directory.
For anyone else who has this issue:
Try taking out the '.py'
django-admin startproject helloworld
firstly find out where the django-admin.py is located then go to that path and then run the command django-admin.py startproject projectName
i hope it will help you......best luck
Using the Bitnami Django Stack
> cd C:\Users\user_user_name\Bitnami Django Stack projects
C:\Users\user_user_name\Bitnami Django Stack projects>
> python C:\Bitnami\djangostack-1.8.17-0\apps\django\Django-1.8.17-py2.7.egg\EGG-INFO\scripts\django-admin.py --version
> python C:\Bitnami\djangostack-1.8.17-0\apps\django\Django-1.8.17-py2.7.egg\EGG-INFO\scripts\django-admin.py startproject projectname
That works for me.

Categories