how to run a django project (made on linux) on windows? - django

I am new to programming and started working on Linux, now I want to switch to windows and open my project there, look at the tutorials, it is written to activate the virtual environment in the Settings / activate.bat folder. but in my project there is no such folder and such file with the extension .bat. what should I do?

Please download & Install interpreter from https://www.python.org/downloads/
(make sure you are using windows 10, because previous
version create problems)
Download pycharm professional addition (if you have university account) other wise go for community https://www.jetbrains.com/pycharm/download/
Click for Django project
Set the interpreter
Go to. manage.py task
Run command migrate
Enjoy

First thing get all the requirements like the library you installed through pip inside
a txt file by writing this command pip freeze > requirements.txt.
Get only the source folder where you made the project and app.
Create a folder.
Create an environment inside the folder. (virtualenv name_of_the_env)
Go inside the env you created and activate the Script. (.\Scripts\activate)
Copy the source folder inside the env and either you can install all the library
manually using pip or you can use requirement.txt that you have created to install the
library by writing this command pip install -r requirement.txt.
You need python and pip installed to work

Related

unable to complete django installation

I downloaded the necessary files from the link https://github.com/django/django.git and pasted them in to my virtual env directory
After setting up and activating the virtualenv, when I run the following command:
$ pip install -e django/
It produces this error:
(ENV) C:\WINDOWS\system32>pip install -e django/ django/ should either
be a path to a local project or a VCS url beginning with svn+, git+,
hg+, or bzr+
I am a Windows user. I think the command is for bash not for cmd.
Is it necessary to use this git tool to finally work with django ?
As instructed on the Django website :
If you're just starting out with Django development I'd recommend looking at some YouTube videos before jumping into the Django docs. Personally when I was starting out I found that the docs were quite hard to understand in the beginning, but as you get better you can refer back to them more and more.
Here's a good beginner video series to get you started.
In any case, I would recommend using virtualenvwrapper-win so that you can work on multiple Django projects without any conflicts.
First, ensure that you have added Python to the Windows environment. Open CMD and run pip install virtualenvwrapper-win.
Then cd to whichever directory your project files will be in and run mkvirtualenv projectname.
Finally run setprojectdir path/to/folder
Now whenever you want to enter that virtual environment and work on your project all you have to do is run the command workon projectname and it'll do the rest for you. You'll know it worked if on each new line in the command prompt it gives you (projectname) in brackets.
To actually install Django all you need to run is pip install django while in the virtual environment.
From your question, I suppose that you are trying to install django inside your virtual directory. If that is correct you dont need to get it from git.
Alternate way is to create a directory "main" and then project directory "mydjangoproject" inside it and a virtual environment "env".
C:\>mkdir main
C:\>cd main
C:\main>mkdir mydjangoproject
C:\main>virtualenv env
Now activate the virtual environment.
C:\main>env\Scripts\activate
Then install all the package in it. e.g
(env) C:\main>pip install django

Where do you install django-registration-redux module?

I have my own project called "polling". I am looking to install the django-registration-redux submodule to create the log-in process. Where should I same the Django-registration-redux module? Another way to ask this is what does the directory structure look like?
Should I save it within the polling directory? or on the same level as polling because it is a separate project that I'm importing?
From the docs:
Automatic installation via a package manager
Several automatic package-installation tools are available for Python; the recommended one is pip.
Using pip, type:
pip install django-registration-redux
Manual installation from a downloaded package
If you prefer not to use an automated package installer, you can download a copy of django-registration-redux and install it manually... From a command line in that directory, type:
python setup.py install
Bottom line, just run the setup installation process and it will "install" it to the right place.

How export python project?

Let me explain elaborately what problem I am facing.
1. I am using Windows environment and pycharm IDE for development of python project.
2. As part of development I am going to use several thrid party python packages say pexpect by installing through pip.
3. Once I am done with development I am going to use python project in Linux environment where I can't install any of these python packages.
So please suggest me way to export python project along with thrid party packages , so that without installing any of 3rd party packages I can run my project in Linux environment.
You have to use virtualenv when you are creating a python project with third party apps. virtualenv is a tool to create isolated Python environments. You can export this project and run in any other environment(Linux, Windows, OSX).
Documentation - Virtualenv
Video - Virtualenv Tutorial
You also need to create a requirement.txt file which will contain your all third party apps. Once you are in virtual environment, you could use the below code:
pip freeze > requirement.txt it will create a requirement.txt file.
For installing all the dependencies again, you need to use:
pip install -r requirement.txt

command "django-admin.py startproject mysite" not recognized

EDIT: I added the path to django-admin.py to my system path (C:\Users\me\Downloads\Django-1.5.1\django\bin) but even after this when I try to run django-admin.py startproject mysite, it asks me to pick a file to open with and even when I pick python.py, it opens in chrome for some reason. I also tried python django-admin.py startproject mysite but it says
python: can't open file django-admin.py: [Errno 2] No such file or directory
Any idea what is wrong?
I added python27 to the system path and when I open up cmd and switch to a directory (C:\Users\me\djcode) and then type in django-admin.py startproject mysite it says
django-admin.py is not recognized as an internal or external command, operable program or batch file
When I try typing the command python django-admin.py startproject mysite, it says
python: can't open file django-admin.py: [Errno 2] No such file or directory
Any idea why?
In the djangobook (http://www.djangobook.com/en/2.0/chapter02.html) it says
django-admin.py should be on your system path if you installed Django via its setup.py utility
what does this mean? how do I add django-admin.py to my system path? I am not sure where django-admin.py even is.
Working !!
If you are using window then first of all
create virtual environment
python -m venv venv
Then activate that environment
venv\Scripts\activate
Then install Django in that environment
pip install django
Then create django project named mysite
django-admin startproject mysite
I have the same problem because i have installed Django Manually. The solution for resolve :
Install Python https://www.python.org/downloads/ (if not installed)
Verify your Path : https://stackoverflow.com/a/17836439 It's very important or the next no work.
Install setuptool : Download the .py file here : https://bootstrap.pypa.io/ez_setup.py and execute this with python.
Install PIP with this command : easy_install pip
Clean Django : pip uninstall django
install Django : pip install django
Execut django-admin.py startproject mysite and enjoy.
If not OK, test django-admin-script.py startproject mysite. If is ok, your django installation is wrong.
Sorry for my bad english, i'm french :)
Find the folder where django-admin.py is located. Then go to Control Panel > System > Advanced System Settings > Environment Variables . In the User Variables and/or System Variables, search for an entry called PATH. Modify it by adding the folder you found earlier, use the other entries as guidance, basically just make sure they're separated by ;. If you have done all these steps, but are still in the same cmd prompt that you were using before doing them, close it and open a new one so it picks up on your changes.
For windows, the "django-admin" you need to create a project is an .exe file not a .py file and it is present at the following location:
C:\Python27\Scripts
so you have to add this location to your path.
After running pip install django wait for the setup to finish and
present you with a warning.
From the warning copy the path of where django is installed. In my
case it is
C:\Users\USERNAME\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8\LocalCache\local-packages\Python38\Scripts
Add that to PATH in environment variables and restart cmd or shell.
Try this: django-admin startproject mysite
I have tried all of the mentioned things however I was still unable to create a project using django-admin startapp appname. So I used python -m django startproject appname instead and was able to create the proejct
If it did not work for you even if you tried the command :
django-admin startproject mysite
Here's what worked for me:
Uninstall django
pip uninstall django
Add the below path to the PATH variables-
C:\Users\System_Name\AppData\Roaming\Python\Python39\Scripts
Note: In the above path, System_Name refers to the name of your laptop/pc.
Install django again
pip install django
You can check the version of django using django-admin --version
I've just created project using :
py -m django startproject Yourprojectname
You need to install django. It seems you have just downloaded it and expanded the archive.
Install setuptools
Install pip
Open a command prompt and then type pip install -U django (or, you can download the windows installer).
Once you have done the above steps, you need to make sure C:\Python27\Scripts is in your PATH; otherwise the commands will not work.
To set PATH, go to Environment Variables from My Computer (right click and then go to Manage, then on the left, Advanced Settings).
Finally, you'll need to run python django-admin.py and not django-admin.py
this one workked for me
python 2.6.6
django 1.6.11
python C:\Python26\Scripts\django-admin.py startproject myapplication
Try using. exe instead of .py.
It worked for me
Add the following address in the system path
C:\Users\{username}\AppData\Roaming\Python\Python39\Scripts
{username} : enter your username
Try this command: python -m django startproject myapp
I faced the same problem and tried many ways. Solved my problem by following these steps
Python installation manually
in my cmd
pip install Django
pip install djangorestframework
pip install django-cors-headers
pip install virtualenvwrapper-win
Windows+r
sysdm.cpl
In Advanced Option, Environment Variables> In user variable edit
path
C:\Users\mushf\AppData\Roaming\Python\Python310
C:\Users\mushf\AppData\Roaming\Python\Python310\Scripts
In System Variable> Edit
path
C:\Program Files\Python310\Scripts\
C:\Program Files\Python310\
After that create my project folder in the desired location:
django-admin start project ProjectName
My preferable IDE is pycharm
Instructions for Windows
You must have pip on your machine.
Open Visual Studio and open the project folder.
Open terminal from VS, Terminal tab. Go to the project directory.
pip3 install virtualenvwrapper
This must be done only the very first time you are setting up your environment.
Then run:
python -m venv env
Installs the needed files for running a virtual environment. You should see a folder added now. Create a virtual environment. Now activate it (i.e. start working in the virtual environment):
activate environment env\Scripts\activate
if activate doesn't work use this
env\Scripts\activate
Install Django in a virtual environment. If you want a specific version run:
pip install django==3.0.3
For the latest version just run:
pip install Django
To check the existing version:
pip freeze
To create a new project:
django-admin startproject simplesite
cd simplesite
python manage.py startapp helloworld
will create a new application in the project with a folder "helloworld"
python manage.py runserver 127.0.0.1:8080
Open in your browser http://localhost:8080 to test the running server.
Ctrl+C to stop the server.
copy the Django-admin.exe file into the folder you are using. the file can be found at python/python(version)/scripts. when you finish a folder should pop up in the name of your file
Just copy the Django admin.py file which is present actually where you have installed python in C:\program files\Python or in my case it was located at administrator\appdata\local\programs\python you can check yours and just copy the file that is Django admin from script folder to your newly created folder
I needed to update my System Environment Variable path so this answer helped me:
Add “django-admin.py” path to command line on Windows
You will have to activate the environment (env) before you run the command:
django-admin startproject myapp
I had the same problem.
For Windows user:
Step 1: Open cmd in the project directory
Step 2: Run this in cmd : python -c "import django; print(django.__path__)"
Step 3: Go to the path and copy django-admin.exe to the current project directory
Step 4: Run this in cmd : django-admin startproject DEMO
Happy Learning,
Thank you
Before you run django-admin.py startproject mysite
1) You need to create a virtual enviroment on the folder that you want to store your project
so run pipenv install django==2.1 (if you dont have pipenv installed run
pip install --user pipenv)
2) To run this virtual enviroment run pipenv shell
3)And finaly django-admin.py startproject mysite
Hope this works
In my case I made a mistake installing django in a wide system manner and then it created /usr/local/bin/django-admin I uninstalled django through pip but it doesn't remove those files then when you type the command it tries to invoke that file but as it says the module django is not present.
Just remove those orphans files (use sudo if needed)
sudo rm /usr/local/bin/django-admin
sudo rm /usr/local/bin/django-admin.py
and try again (with your virtualenv activated) and it should takes the right module and works as usual!
This is my solution:
step-1 --add environmental path
C:\Users\DELL\AppData\Local\Programs\Python\Python38
C:\Users\DELL\AppData\Local\Programs\Python\Python38\Scripts
step-2 pip install django
step-3 --run command in specific folder
django-admin.py startproject mysite
For me, a simple fix was reinstalling python. It turns out I didn't select add to path, when installing python the first time, and that is crucial.
if you are using windows then goto (search)"advanced system settings/Environment veriables/New path" and add path of your python packeges folder, in my case its "C:\python38\Lib\site-packages".
may be you have other path of site-packages folder.
If you are using Pycharm then after creating New project just go to the file-->setting-->project-->serch Django-->install Django then go to the terminal type django-admin startproject name(whichever you want) press enter
Run CMD as Administrator
pip3 install django
If you had this error occur on windows after installing django using pip that has the message along the following lines:
could not install packages due to an OSError: [WinError 2] The system
cannot find the file specified: 'c:\python39\Scripts\sqlformat.exe'
-> 'c:\python39\Scripts\sqlformat.exe.deleteme'
Which in turn causes the same problem as the question stated. A working solution is to clean installing django which you can do by using pip uninstall django, and then reinstalling it by running the install command like this: pip install --user django.
If no other warnings or errors occur, then it should be fixed. In case a warning sating that the django-admin.exe file is located at some location that needs to be added to the path variable, you can copy that path and add it to the path variable under your environment variable settings.
Quick fix guide:
Uninstall django: pip uninstall django.
Reinstall django: pip install --user django.
If a warning occurs containing a path continue to step 4 otherwise it should be fixed, and you may skip to the bottom.
Copy the path that should be added to the PATH environment variable.(the one specified in the warning)
Click on the start menu button.
Search for Control Panel and click on it.
Change the View by: option to Large icons.
Click on the System item.
Click on the Advance system settings button.
The System Properties window will open, proceed to click on the Environment Variables... button at the bottom right.
A new window will open displaying your Environment Variables, on the first gird select the row with the name of PATH or Path or path under the Variable column.
Then click the Edit button just below the grid.
A new window will open, proceed to click on the New button and paste the path you copied earlier.
After pasting press the Enter key and proceed to click on the OK button.
Once the window closes and you're back in the Environment Variables window proceed to do steps 11 to 14 again only with the grid at the bottom(inside the System Variables group).
Once all these steps were followed you may click on the OK button in the Environment Variables window and close out of all the other windows that are still open after you followed these steps.
Close your CMD window and open a new one (this allows it to recognize the changes you made to your environment variables).
After following these steps, you should be able to continue with what you were doing without having any other difficulties further regarding Django
I wasn't getting the django-admin to run even after an hour of configuring PATH etc. That was all completely useless.
What actually WORKED was running the windows terminal (cmd) as admin and then doing "pip install django". Be sure to first uninstall it though using "pip uninstall django", so that you get a clean installation.
Now django-admin runs perfect on cmd with or without admin rights.

VirtualEnv is installed, but cannot find bin/activate

We had a working project with git, and our instructor moved our project over to mercurial after making some changes.
I pulled the new project and started it up under a new folder.
I tried running a virtualenv for the new project but I get: Requirement already satisfied
I would usually then run $ . bin/activate but I cannot find a bin folder.
How do I get a virtualenv setup for this project at this point?
The place where you have your project isn't necessarily the place where you have the environment. Did you have the environment in git too?
Perhaps what you need to do (in case you don't have a versioned environment) is recreate the environment (virtualenv environment), install the dependencies (pip install -r req.txt) and then activate it (source path/to/environment/bin/activate).
Good luck.
Ok
Try this an awesome link to How to install django in virtual environment .
http://ayarshabeer.com/post/50973941605/install-multiple-django-version-using-virtualenvwrapper
Use the following steps
virtualenv virenv_name --no-site-packages - create new virtual environment in git
pip install -r requirements.pip - It can be used for install tools in
(requirements.pip files)
yolk -l - It will used for list install files
source git/virenv_name/bin/activate - Activate virtualenv
deactivate - Deactivate virtualenv