I have python, pip and django installed. I have created a virtual environment, installed Django inside it and trying to create a new project via the following command:
(venv)c:\Users\username\Desktop\venv>.\Scripts\django-admin.py startproject test_project
Instead of creating the folder test_project along with its file, my PyCharm ide automatically starts and opens the django.admin.py file.
When I check inside my venv folder, only the default folders exists and test_project is not created. Can I know how to fix this please.
django-admin startproject test_project
it should be django-admin, not django-admin.py, If I remember correctly, it is new since 1.7
Related
I've been following a tutorial on how to start using django and creating a virtual env on VS Code, but it doesn't work.. For what it shows in the tutorial, it's supposed to create a folder called ".vscode" with a json file inside called "settings.json" that contains the python path to the python interpreter..
But in my case, none of those files appear.. I THINK there might be sth wrong with the path where it creates the virtual env, but since I'm pretty new at this, I can hardly say..
This are the steps I followed:
C:\Users\Usuario\Desktop\Andres\Programación\5. Prácticas\3. PYTHON>cd DJANGO
C:\Users\Usuario\Desktop\Andres\Programación\5. Prácticas\3. PYTHON\DJANGO>mkdir storefront
C:\Users\Usuario\Desktop\Andres\Programación\5. Prácticas\3. PYTHON\DJANGO>cd storefront
C:\Users\Usuario\Desktop\Andres\Programación\5. Prácticas\3. PYTHON\DJANGO\storefront>pipenv install django
C:\Users\Usuario\Desktop\Andres\Programación\5. Prácticas\3. PYTHON\DJANGO\storefront>code .
C:\Users\Usuario\Desktop\Andres\Programación\5. Prácticas\3. PYTHON\DJANGO\storefront>pipenv shell
(storefront-vT5YbUlq) C:\Users\Usuario\Desktop\Andres\Programación\5. Prácticas\3. PYTHON\DJANGO\storefront>django-admin startproject storefront .
(storefront-vT5YbUlq) C:\Users\Usuario\Desktop\Andres\Programación\5. Prácticas\3. PYTHON\DJANGO\storefront>pipenv --venv
** So the command prompt returns me this:
C:\Users\Usuario\.virtualenvs\storefront-vT5YbUlq
I'm supposed to copy that line to "Enter interpreter path" in VSCode, and after that it should create those vscode folder and json file.. but that doesn't happen, so I can't use the VS terminal to run the server
I'm going insane with this, I just can't understand where's the problem
I'd really appreciate if someone could help me with that
Thanks!
using terminal, mkdir to make a directory for your project
cd to your project folder/dir
type code . to open up vs code in this directory
Now you can use the integrated vs code terminal, please select the terminal, not the powershell
type pip3 freeze, it will show up all the installed packages and dependencies on global scope/system
but we gonna have a venv where we will install our necessary packages and dependencies
type python3 -m venv ./venv to create venv inside your current project folder, please ensure you are inside the folder before running this command
[if you are not using python 3, then the command will be python -m venv ./venv]
to actiavte environment,
on mac, run source ./venv/bin/activate
on windows, run .\venv\Scripts\activate.bat [if it doesn't work, try to put your absolute path]
you can check what is installed inside venv using pip freeze, you will see nothing inside the venv
Now you can install django inside venv for your project
inside vs code, press shift+cmd+p and search for Python: select interpreter and choose venv [enter interpreter path>find>project folder>venv>Scripts>python.exe]
then you can notice the settings.json file inside .vscode folder in your project
to deactivate the environment, just type deactivate
Still, if you don't see the .vscode folder inside your project folder, you can create it manually.
Create a folder and name it .vscode
inside the folder, create setting.json file and paste the following code
{
"python.analysis.extraPaths": [
"./YOUR_PROJECT_FOLDER_NAME",
]
}
for instance, system search for custom modules here in this extraPath if the module is not available in your system or user environment path.
You can try to follow this tutorial on the VSCode official docs.
You don't need to create the settings.json file, it was created by the VSCode, you can refer to here for the details.
And the interpreter-related information you can refer to here.
I am trying to create a project in a virtual environment in Ubuntu 16.04
I am using Python 3.6
What I do so far is
sudo bash
cd Desktop/DamLevels-course2/Damlevels2/
source venv2/bin/activate
django-admin.py startproject dams
The error says: ImportError: No module named 'secrets'
I have checked the list of modules in python and secrets is there, but when I try to import to the virtual environment I get an error saying : import: not authorized 'secrets' # error/constitute.c/WriteImage/1028
I tried adding the shebang line as well (#!/usr/bin/env) but that didn't seem to work; running the startproject line again results in the same error message as before.
I am very new to all of this, so I would appreciate fairly simple help.
Ok I think I got it to work. Instead of using
django-admin.py startproject *name*
i used
django-admin startproject *name*
First I had to install python-django
Thanks for your help everyone!
The Django documentation states the command to create a new project is:
$ django-admin startproject mysite
So to create your project replace "mysite" with "dams", or whatever your project name will be. For example:
$ django-admin startproject dams
Also, perhaps it was a typo but the package that should be installed is "python3-django", not "python-django". This command will install python3-django.
$ sudo apt-get install python3-django
The Django documentation also references potential problems running django-admin. Here is an excerpt mentioning issues between django-admin and django-admin.py.
Problems running django-admin
command not found: django-admin
django-admin should be on your system path if you installed Django via
pip. If it’s not on your path, you can find it in
"site-packages/django/bin", where site-packages is a directory within
your Python installation. Consider symlinking to django-admin from
some place on your path, such as /usr/local/bin.
If django-admin doesn’t work but django-admin.py does, you’re probably
using a version of Django that doesn’t match the version of this
documentation. django-admin is new in Django 1.7.
Basic Information: I am completely new to Django, and have been attempting to follow their documentation. When I attempt to run the code shown here, it comes up with an error:
django-admin startproject website
Error message:
django-admin is not recognized as an internal or external command, operable program or batch file. (https://gyazo.com/5159e172f1d0235b49db4fb4a73469cc)
System Information: Python version: 3.6.3, Computer Operating System: Windows 10, Django version: 2.0.5
1) Firstly,
Check wether django-admin.py file is in 'PythonXX\Scripts' folder and that folder is added to System Environment Variables, (PATH) of Windows 10.
If not, it can be added with C:\> set PATH=%PATH%;C:\PythonXX\;C:\PythonXX\Scripts\
2) If that does not work;
Setup a virtual environment named ANY, in the directory where you want to start your django project: C:\some_path> python -m venv ANY.
Start the virtual environment: C:\some_path\ANY\Scripts\activate.bat. If things went right, name of the running virtual environment will be included at the beginning of the command line prompt like: (ANY) C:\some_path\ANY\Scripts>
If django is not installed into the running virtual environment, no django application will be recognized and be able to run by the command line.
Therefore, install django: (ANY) C:\some_path> python -m pip install django. It doesn't matter where you ran that last code, in a running virtual environment.
The virtual environment must be started before running any django application.
Start a django project: (ANY) C:\some_path> django-admin startproject website
I hope those helps...Good luck.
I am just starting Django these days but I cannot run this command
django-admin.py startproject myproject
Well, CMD does not prompt to say that this command is not recognized. Instead, it just open up my Sublime with the file django-admin.py open. and of course no folder named myproject is created inside the current folder.
I managed to start a Django project by typing commands like
python C:\Python27\Scripts\django-admin.py startproject myproject
But when I omit the part about the absolute path information of django-admin.py, then the command does not work, saying python cannot find such a file inside the current directory.
is there any way I should try to use shorter commands? (PS: I do have C:\Python27\ and C:\Python27\Scripts\ in the PATH)
The easiest way (recommended by the docs) is to just copy django-admin.py to your project's directory.
Technical details: There are workaround in setuptools to make entry points work correctly on Windows, by installing a .exe file that will run correctly even if Python is not set as the default handler for .py files, but Django is not using setuptools but distutils directly. I am not aware of any discussion about moving to setuptools.
Alternatively you can set python.exe as the default program to open .py files, instead of your text editor.
In the past I have had a similar issue on windows. I found that using django-admin as listed below worked.
django-admin.py startproject myproject
I found that it was easy to copy the file django-admin.py into the folder that I wanted the stuff in. Navigate to the file in the command line and then run.
'python django-admin.py startproject myProject'
I have just started using python3.4 and I found everything (packages like pip and django) in c:\pythonpath\scirpts dir. Added that into system path and everything works good. e.g. django-admin startproject mysite
I have added C:\Python27\ for python and C:\Python27\Lib\site-packages\django\bin\ for django to the path variable of environment settings.
But whenever I am running the command
django-admin.py startproject myapp
it is simply opening the django-admin.py file in notepad and not creating any custom django directory and file structure.
I am not able to start with my app development. I didn't faced any problem when I work on ubuntu.
try python django-admin.py startproject myapp
also make sure you have properly installed python ... it should auto-associate files ending in .py