Category: Python
What is Pipenv for Python?
Why I need pipven?
Pipenv is a packaging tool for Python that solves some common problems associated with the typical workflow using pip, virtualenv, and the good old requirements.txt.
Pipenv is a dependency manager for Python projects. If you’re familiar with Node.js’ npm or Ruby’s bundler, it is similar in spirit to those tools. While pip can install Python packages, Pipenv is recommended as it’s a higher-level tool that simplifies dependency management for common use cases.
nstalling packages for your project
Pipenv manages dependencies on a per-project basis. To install packages, change into your project’s directory (or just an empty directory for this tutorial) and run:
On ubuntu:
$ mkdir myproject
$ cd myproject
$ pipenv install requests
Creating a virtualenv for this project...
Pipfile: /media/ukkgoodbye/Python/PythonDjangoWithMosh/myproject/Pipfile
Using /usr/local/bin/python3 (3.11.1) to create virtualenv...
⠼ Creating virtual environment...created virtual environment CPython3.11.1.final.0-64 in 303ms
creator CPython3Posix(dest=/home/iwc46/.local/share/virtualenvs/myproject-2c8shx2v, clear=False, no_vcs_ignore=False, global=False)
seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/home/ukkgoodbye/.local/share/virtualenv)
added seed packages: pip==23.0, setuptools==67.1.0, wheel==0.38.4
activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator
✔ Successfully created virtual environment!
Virtualenv location: /home/ukkgoodbye/.local/share/virtualenvs/myproject-2c8shx2v
Creating a Pipfile for this project…
Installing requests…
Resolving requests…
Installing…
Adding requests to Pipfile’s [packages] …
✔ Installation Succeeded
Pipfile.lock not found, creating…
Locking [packages] dependencies…
Building requirements…
Resolving dependencies…
✔ Success!
Locking [dev-packages] dependencies…
Updated Pipfile.lock (ff88c6939e3090788e917cfdecf1af872168b83c8803457853061495493b5a71)!
Installing dependencies from Pipfile.lock (3b5a71)…
To activate this project’s virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.
For example for the project: e-smatsolution
$ cd e-smartsolution
Activing the pipven environment of the project
~esmartsoltion $ pipevn shell
Creating dhango admin
~esmartsoltion $django-admin startproject esmartsolution .
by adding “.” is tell django-admin to create the project inside the current folder.
To run the server:
python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
You have 17 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run ‘python manage.py migrate‘ to apply them.
February 16, 2023 – 07:43:02
Django version 2.2.12, using settings ‘esmartsoltion.settings’
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[16/Feb/2023 07:43:09] “GET / HTTP/1.1” 200 16348
Not Found: /static/admin/css/fonts.css
[16/Feb/2023 07:43:09] “GET /static/admin/css/fonts.css HTTP/1.1” 404 2017
[16/Feb/2023 07:43:23] “GET /admin/ HTTP/1.1” 302 0
[16/Feb/2023 07:43:23] “GET /admin/login/?next=/admin/ HTTP/1.1” 200 1816
Not Found: /admin/login/static/admin/css/responsive.css
Not Found: /admin/login/static/admin/css/base.css
Not Found: /admin/login/static/admin/css/login.css
[16/Feb/2023 07:43:23] “GET /admin/login/static/admin/css/base.css HTTP/1.1” 404 3782
[16/Feb/2023 07:43:23] “GET /admin/login/static/admin/css/responsive.css HTTP/1.1” 404 3800
[16/Feb/2023 07:43:23] “GET /admin/login/static/admin/css/login.css HTTP/1.1” 404 3785
[16/Feb/2023 07:43:23] “GET /admin/ HTTP/1.1” 302 0
[16/Feb/2023 07:43:23] “GET /admin/login/?next=/admin/ HTTP/1.1” 200 1816
Not Found: /admin/login/static/admin/css/responsive.css
[16/Feb/2023 07:43:23] “GET /admin/login/static/admin/css/responsive.css HTTP/1.1” 404 3800
Djando-admin won’t load the css!
Runing a django project
Run migrations
python manage.py migrate
Create superuser
python manage.py createsuperuser
Start development server
python manage.py runserver
Access http://127.0.0.1:8000/admin/
Login with your superuser. You should get an error connecting to the server.
Check the running server. It should not be running.