Here's are the commands i'm using to start my project:
nginx -s stop
workon my_project_env
pkill -f uwsgi -9
uwsgi -x /root/my_project/My_web_api/My_web_api.xml
deactivate
nginx
I want to make sure that this project starts even if the server reboots.
But writing a shell command file as xxx.sh is not going to work,
as shell command won't simply work in virtualenv.
All of the command above will just work in the main terminal,
but some command must work on the virtualenv.
How can i work this out?
You will need to call the uwsgi command using the virtualenv's file for uwsgi. that way you won't need to activate the virtualenv.
Something like below,
/path/to/virtualenvs/project-name/bin/uwsgi -x /root/my_project/My_web_api/My_web_api.xml
All the commands that need to be run using virtualenv should be called this way, so that you won't need to activate the virtualenv.
I found out that using souce ./xxx.sh will work(i used to use ./xxx.sh ), but with Akash Ranjan's help, i know that it is not the right way for situation like this.
I have the following problem (I searched for hours but could not get it to work):
I have a python cli application (coded by myself). I created a fresh conda environment (with python 3.9.1) and installed myapp locally via pip install . into the env. All went well and I could successfully run myapp from the cli without any errors.
However, part of my application needs myapp to be called with sudo. By doing so, I received the error: Command not found: myapp.
My question is now: Why is this happening (Is this, because my env is somehow not correctly activated or "linked"?)?. I read, that sudo uses some other paths in its $PATH. But how can I fix this?
Any ideas are welcome ;)
Many thanks in advance
Edit: I also tried this using virtualenv but same result. Furthermore, I could successfully run the same app with sudo on my other system, so it must has something to do with my Ubuntu (18.04) system.
I have to run the following set of commands after opening a windows cmd prompt
D:
cd Dev\project\backend
.\venv\Scripts\activate
python manage.py runserver
How to write a script(.bat) file for running these commands and the runserver will stay showing the output
I tried to put these commands in django.bat and double click, but a cmd window opens and within a fraction of second it closes. Dont know what happened
Instead of activating the venv then running manage.py separately, you should run directly using the python.exe from your virtual env.
It should look like this:
> D:\Dev\project\backend\venv\Scripts\python.exe D:\Dev\project\backend\manage.py runserver
I don't really know what you intent to use this for, but in windows you should run your Django project using IIS. Check out django-windowsauth, you can use it to run Django on IIS in few commands. https://github.com/danyi1212/django-windowsauth.
Just skip adding the middleware and the authentication backend of you don't need Windows Authentication on your site.
I tried to do this recently, but had to move onto something else quickly; given your question it's a nice opportunity to return to it, and I believe I've found the answer!
From what I found on my Laptop just now, the issue is with the activate line
.\venv\Scripts\activate
On Windows, this is another .bat file, and I suspect that calling it runs in a new cmd instance, rather than the current one
So I simply copied the entire contents of activate.bat and put it into my custom script, and it worked!
#echo off
cd D:\Dev\project\backend
-> Paste entire contents of activate.bat on this line <-
.\manage.py runserver
I'm using python 3 and have many virtual envs using pyvenv on mac osx 10.9.3. In all of them the command ./ runs my python code. In one of my envs the command has stopped working and I can not find anything about how to get it to begin working again.
EDIT: I get permission denied when typing out the whole file instead of tab (i.e. ./manage.py), and when I add sudo it works, but all the other venvs don't require sudo.
I'm searching through pyvenv docs and searching through various bash links but can't get it to restore or know where that shortcut comes from.
When I type python [file] everything works as expected, but I want to restore the ./[file] I know it's going to be something easy but for some reason I can't figure out what to search to get the relevant solution.
When you type ./[tab] and the file you're expecting doesn't come in linux shell, chances are you need to make the file executable:
sudo chmod a+x manage.py
Or you don't have sufficient permissions to access the file:
sudo chown user:group manage.py
(Be careful with the last one because it may lead to unexpected behaviour)
I'm new to django and currently going through the main tutorial. Even though it was working earlier, when I do python manage.py runserver OR python manage.py -h OR with any other command, the shell doesn't output anything. Wondering what I'm doing wrong.
The problem is that the first line in manage.py breaks the file on windows.
The first line should look like this:
#!/usr/bin/env python
Removing it will fix the issue.
First, check if python is fully installed by typing "python" in a shell.
Then you should try python manage.py runserver inside your django project. If you don't have any django project, try creating one by typing django-admin.py startproject mysite. If nothing is displayed in your shell, you must have installed Django the wrong way.
Please refer to Django Documentation at https://docs.djangoproject.com/en/1.4/intro/install/
If you had your server running till one point and a certain action/change broke it, try going back to the previous state.
In my case there was an email trigger which would put the system in an invalid state if email doesn't go through. Doing git stash followed by selectively popping the stash and trying the runserver helps narrow down the problem to a particular file in your project.
Please try this.
Uninstall Python.
Go inside C drive and search Django. You will get many Django related files.
Delete every Django file. đ don't delete your Django files.
Install Python.
It's worked for me.
if you created a virtual environment then activate it. you can try this command(in virtual environment directory) if you're using windows os:
.\Scripts\activate
On Ubuntu works for my by running manage.py as script:
./manage.py runserver
Just stuck with the same problem. Found a solution that works, but tedious.
You need to know the location of the python.exe file in your computer. It is usually
C:/Users/USERNAME/AppData/Local/Programs/Python//python.exe
Modify as required and run the following in CMD,
C:/Users/USER1/AppData/Local/Programs/Python/Python38-32/python.exe
F:/mysite/manage.py runserver
Hope this works :)
if you are using Redis Server on Windows, check it out if Redis Server is running, I had same problem and realized my Redis Server was not running, I ran it and now my manage.py commands work fine.
The same happened with me also, but this issue is a minor one as it happens if you have multiple versions of Python on your system, you can select a specific Python version by running python3 or whichever version you want.
SO you should start from the beginning, uninstall Django first then,
create a virtual environment, decide upon a directory where you want to place it, and run the venv module as a script with the directory path:
for e.g:
python3 -m venv tutorial-env
//This will create the tutorial-env directory if it doesnât exist, and also create directories inside it
Once youâve created a virtual environment, you may activate it.
On Windows, run:
tutorial-env\Scripts\activate.bat
On Unix or MacOS, run:
source tutorial-env/bin/activate
Now,
In the command prompt, ensure your virtual environment is active, and execute the following command:
...> py -m pip install Django
NOTE:
If django-admin only displays the help text no matter what arguments it is given, there is probably a problem with the file association in Windows. Check if there is more than one environment variable set for running Python scripts in PATH. This usually occurs when there is more than one Python version installed.
Another solution, if you can, is to upgrade Django
pip install django --upgrade
Oftentimes one will get other unrelated issues to solve that are linked with the upgrade but once all is fixed the server should run just fine.
If you can't upgrade Django, this problem also happens when the code was built using Python 2.x and you're locally using Python 3.x.
The quicker fix in that case is to uninstall Python 3.x from your machine and make sure Python 2.x was added to the path. I've seen some developers setting up alias in PowerShell to have more than one version in the environment too.
I think the problem is in manage.py file (50%), check it with an another file that is correct.