I have a number of packages in the requirements.txt file. I need to list which packages are used in the Django project and Which packages are not used in the Django project using the command prompt. Is it possible?
From your question, it's not clear if you're looking for this, but from what I've gathered, I think you may find just what you want in this thread. How to see unused dependencies in requirements.txt?
If you used any virtual environment like VENV, PIPENV etc. You can run you virtual env and in command prompt , use this command: pip freeze >> requirements.txt
This will have all the packages used in this project.
Related
I have a problem with using virtualenv and django in bash. If I type python -m venv env in cmd, then env\Scripts\activate, and then virtualenv - I get 'virtualenv' is not recognized as an internal or external command, operable program or batch file.. If I do the same in bash I get bash: virtualenv: command not found. How do I fix this?
Try the following to resolve your issue.
Check all of the environment variables related to the software you require to be used at least.
Check the permissions for files and folders for the software.
Sometimes uninstalling and installing the software with issues can solve problems quickly.
If you have performed number 2. and you are still have errors, proceed to number 3.
You may have dependencies missing, a good tool i have used on Windows is Dependency Walker, and the software will check if any file and dependencies are missing, and you should be able to download them.
An error message may output a file is not found but in fact a dependency is missing, relating to the software you are trying to run.
Try the following steps in the terminal, it may solve your problem.
using terminal, mkdir to make a directory for your project
cd to your project folder/dir
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
to deactivate the environment, just type deactivate
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
Good day.
I'm a newbie to Django and I have a slight confusion:
When deploying my Django app, do I need to deploy it with all the Python 'come-with' modules, or the hosts already have them installed.
Also, I installed PIL for image manipulation. Would they also have it installed or i have to find a way to install it on their servers. Thanks in advance
do I need to deploy it with all the Python 'come-with' modules
Never do that. It might conflict with the dependencies on the server. Instead issue the following command to create a dependency file (requirements.txt).
pip freeze > requirements.txt (issue this command where manage.py is located)
On the server create a new virtual environment. Now copy django project to the server (you can do this using git clone or just plain old Filezilla). Activate virtual environment. Then change you current working directory to the where manage.py is located. to install all the dependencies issue the following command.
pip install -r requirements.txt
This will install the required dependencies on on server.
I created a Django's application which use some additional modules like crispy_forms. I would like to send this application to my friends to test it.
But I don't know how can they just install it and run it? Is it possible?
Application using also database PostgreSQL.
What is the simplest way to just run this application from any place with no errors and problems on the start?
I found only information about https://docs.djangoproject.com/en/1.10/intro/reusable-apps/
and packed my app, but I don't know how to install it.
To setup env for project i would install virtualenv, then:
pip install -r requirements.txt
You need to set database connection in settings.py, or switch to sqlite3...
hope this helps!
If you are using virtual environment then activate it and go in your project root.
If you are not using virtualenvironment then do the same thing, go in your project root.
Make sure you have requirements.txt file.
run the command
pip freeze > requirements.txt
This will add automatically all your modules to requirements.txt file
which can be then installed by
pip install -r requirements.txt
So I have been developing my first django web application over the past few months and I have installed a number of packages that I wanted to try and use to solve some of my problems. However, some of these packages I installed, tried to use, failed, and then never uninstalled.
Is there a way to see what packages my application is using from the list given from "pip freeze"?
That way I can uninstall some of the clutter in my application. Is it a huge disadvantage to have this clutter?
In future development I will uninstall packages right away if I do not use them. So lesson learned :).
A method I use is with my requirements.txt files. From the root of my Django project, I create a requirements/ directory with the following files in it:
requirements/
base.txt
dev.txt
prod.txt
temp.txt
base.txt contains packages to be used in all environments such as Django==1.8.6.
Then dev would include base and other packages, and might look like:
-r base.txt
coverage==4.0.2
Then temp.txt includes dev.txt and contains packages I'm not sure I'll use permanently:
-r dev.txt
temp_package==1.0
git+https://github.com/django/django.git#1014ba026e879e56e0f265a8d9f54e6f39843348
Then I can blow away the entire virtualenv and reinstall it from the appropriate requirements file like so:
pip install -r requirements/dev.txt
Or, to include the temp_package I'm testing:
pip install -r requirements/temp.txt
That's just how I do it, and it helps keep my sandbox separate from the finished product.
Potentially, you could use isort and run isort myproject/* --diff to get a list of proposed changes isort would make to your project.
In the proposed changes, it list imports that are not used. From that, you could take a look at packages installed in your virtual environment and start removing them with pip. This is assuming you did not remove the import statements, which may not be the case.
Another way would be to create a new env and attempt to run your app. Use error messages to get the packages you need until your app runs. Not pretty, but it would work.