Installing Django app from GitHub [duplicate] - python

This question already has answers here:
How to run cloned Django project?
(7 answers)
Closed last year.
create virtualenv
create project (chat)
follow instructions at
https://github.com/qubird/django-chatrooms, after which there is a src folder in the root of the virtualenv
navigate to virtualenv/src/chatrooms and run the command python setup.py install, this installs app folder with all files and folders at virtualEnv/src/chatrooms/chatrooms
How do I get this to install to my project, not to virtualEnv/src/chatrooms/chatrooms? I also checked
Can't install Django app from git
and
how can i download code from git hub using command line but am still stuck.

Just follow these:
cd in to the directory where you want your project to store you source code eg. home/.
Then run django-admin startproject chat
This will create a chat directory in your current directory
Now cd to the chat directory.
run virtualenv env
This will create a directory namely env. Now just activate the virtualenv by running source /env/bin/activate (if you are in the chat dir).
As you now have you virtualenv ready and activated, just installed all your apps by running pip install .. and you are ready to go.
And don't worry about the env folder and its content or where your installed app code goes (until you want to change something in the installed app, which is usually not the case).
All you have to see is if your installed app works or not.

The method below installs directly to the prjoect level directory with no nedd to manually move file , .ie, not installed to src/chatrooms/charooms
1 create virtualenv (optional)
2 create project
3 cd to project
4 run git init
5 run command git clone "{protocol:url}"
6 add app to settings & and urls to main UURLCONF file

Related

How do I create a django project on my D: drive?

I'm new to python and django and wanted to create a django project on my D drive. However, in order to create the django project I have to do it through the terminal and it seems to automatically create the django project in my C drive. How can I change that location?
go to your D drive . Create A Folder . Name it as you want .
Then open this folder in Pycharm. and follow this commands
1. pip install virtualenv (for windows user)
2. virtualenv myenv (myenv is your virtual environment name. You can give anything as you want)
3. .\myenv\scripts\activate (activate virtualenv)
4. pip install django==2.2.10
5. django-admin startproject dj (dj is the project name. You can give anything)
6. cd dj
7. python manage.py runserver
*You can follow the following steps
1.Open your command prompt
.Run the following commands step by step by pressing enter:
a. D: (This will take you to your D drive)
b. mkdir Django-Project (This
will make a folder in D drive)
c. cd Django-Project
d. django-admin
startproject project1 (This will create a project name project
inside Django-Project)

Execute `pipenv` commands from within python script

I am trying to automate setup of a bunch of Python repos:
repo = Repo(repository_path)
# switch to `master` branch
try:
repo.git.checkout("master")
except GitError:
logger.error("Branch `master` does not exist.")
return
# if virtual environment directory does not exist run pipenv install command
if not repository_path.joinpath(".venv").exists():
os.chdir(repository_path)
subprocess.call("pipenv install")
I am executing this from another venv and it seems that packages are installed inside current venv.
In fact I need to call pipenv update to update Pipfile.lock on bunch of repos but there are cases when venv is not set up at all.
Any hint how to run pipenv from within python script without interfering current venv ?

How to run previously created Django Project

I am new to Django. I am using Python 3.7 with Django 2.2.6.
My Django development environment is as the below.
I am using Microsoft Visual Studio Code on a Windows 8.1 computer
To give the commands I am using 'DOS Command Prompt' & 'Terminal window' in
VS Code.
Created a virtual environment named myDjango
Created a project in the virtual environment named firstProject
Created an app named firstApp.
At the first time I could run the project using >python manage.py runserver
Then I had to restart my computer.
I was able to go inside the previously created virtual environment using
workon myDjango command.
But my problem is I don't know how to go inside the previously created project 'firstProject' and app 'firstApp' using the 'Command prompt' or using the 'VSCode Terminal window'
Thanks and regards,
Chiranthaka
Simply navigate to the folder containing the app you want to manage using the command prompt.
The first cd should contain your parent folder.
The second cd should contain the folder that has your current project.
The third cd should be the specific app you want to work on.
After that, you can use the python manage.py to keep working on your app.
Your concern is that you just have to guide your way into the correct folder using the command cd. As in this example:
1. C:\Users\User: cd MainFolder
2. C:\Users\User\MainFolder: cd firstProject
3. C:\Users\User\MainFolder\firstProject: dir (or ls -la for linux, to list all files etc.)
16-Apr-19 07:14 <DIR> .
16-Apr-19 07:14 <DIR> ..
15-Apr-19 21:50 <DIR> .idea
15-Apr-19 21:43 195,961 firstApp.py
Just a roughly tree structure below to show how it is visualized:
C:
|
|---Main folder
|
|---firstProject (if this is your folder)
|
|---firstApp (this is your app)
Go to the directory where manage.py file of your Django project is present. It is normally the Base directory of your project.
In that directory, Press Shift and Right Click at the same time.
The from the Right Click Menu, Click on "Open PowerShell window here".
If you have previously frozen the dependencies, you should download them first through requirement.txt file using command:
pip install -r requirements.txt
Then run start server command in your PowerShell window.
python manage.py runserver
You will see output like this in PowerShell:
Validating models...
0 errors found
November 10, 2019 - 17:36:02
Django version 1.5, using settings 'my_django15_project.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Open the address e.g in above case it is http://127.0.0.1:8000/ in your browser, and you will be able to see your project.

virtualenvwrapper: how to update project path?

When I move a project folders I have to manually update the project path in the .project file to get the workon command to work. Is it possible to update the path automatically?
According to the docs you can use setvirtualenvproject. This will automatically move you to the project folder if you use the workon command:
bono~$: setvirtualenvproject ~/.virtualenvs/your-virtual-env/ ~/path/to/your/project
Or, as beruic mentioned, it's easier to activate the environment and move to your desired working directory first. Please note that this not always work on my system, but it is a lot easier if it does work for you:
$ workon your-virtual-env
$ cd ~/path/to/your/project
$ setvirtualenvproject
In the future it might also be handy to specify the project path for the virtualenv on creation. You have to specify the project with the -a flag.
The -a option can be used to associate an existing project directory with the new environment.
You can use it something like this:
bono~$: cd ~/your/project
bono~$: mkvirtualenv my-project -a $(pwd)
The next time you use workon you will automatically be moved to your project directory.
Alternative
If you want to automatically detect directory changes and set the correct virtualenvwrapper then and there you can have a look at this post. It's a bit too expansive to go into detail here, but I think you can find what you're looking for there if that's what you meant.
You can just activate your virtual environment, go to the folder you want as project folder and call setvirtualenvproject:
$ workon [your_project]
$ cd [desired_project_folder]
$ setvirtualenvproject
Then the current folder will be set as project folder in the current virtualenv.

How to use virtualenvwrapper in Supervisor?

When I was developing and testing my project, I used to use virtualenvwrapper to manage the environment and run it:
workon myproject
python myproject.py
Of course, once I was in the right virtualenv, I was using the right version of Python, and other corresponding libraries for running my project.
Now, I want to use Supervisord to manage the same project as it is ready for deployment. The question is what is the proper way to tell Supervisord to activate the right virtualenv before executing the script? Do I need to write a separate bash script that does this, and call that script in the command field of Supervisord config file?
One way to use your virtualenv from the command line is to use the python executable located inside of your virtualenv.
for me i have my virtual envs in .virtualenvs directory. For example
/home/ubuntu/.virtualenvs/yourenv/bin/python
no need to workon
for a supervisor.conf managing a tornado app i do:
command=/home/ubuntu/.virtualenvs/myapp/bin/python /usr/share/nginx/www/myapp/application.py --port=%(process_num)s
Add your virtualenv/bin path to your supervisord.conf's environment:
[program:myproj-uwsgi]
process_name=myproj-uwsgi
command=/home/myuser/.virtualenvs/myproj/bin/uwsgi
--chdir /home/myuser/projects/myproj
-w myproj:app
environment=PATH="/home/myuser/.virtualenvs/myproj/bin:%(ENV_PATH)s"
user=myuser
group=myuser
killasgroup=true
startsecs=5
stopwaitsecs=10
First, run
$ workon myproject
$ dirname `which python`
/home/username/.virtualenvs/myproject/bin
Add the following
environment=PATH="/home/username/.virtualenvs/myproject/bin"
to the related supervisord.conf under [program:blabla] section.

Categories

Resources