logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

pipenv - Python package manager based on virtual env and Pipfiles

Author

       Python Packaging Authority

Installing Packages For Your Project

       Pipenv manages dependencies on a per-project basis. To install a  package,  change  into  your  project’s
       directory (or just an empty directory for this tutorial) and run

          $ cd myproject
          $ pipenv install <package>

       NOTE:Pipenvisdesignedtobeusedbynon-privilegedOSusers.ItisnotmeanttoinstallorhandlepackagesforthewholeOS.RunningPipenvasrootorwithsudo(orAdminonWindows)ishighlydiscouragedandmightleadtounintendbreakageofyourOS.PipenvwillinstallthepackageandcreateaPipfileforyouinyourproject’sdirectory.ThePipfileisusedtotrackwhichdependenciesyourprojectneedsincaseyouneedtore-installthem,suchaswhenyoushareyourprojectwithothers.Forexamplewheninstallingtherequestslibrary,youshouldgetoutputsimilartothis:$pipenvinstallrequestsCreatingavirtualenvforthisproject...Pipfile:/home/matteius/pipenv-triage/test_install2/PipfileUsingdefaultpythonfrom/mnt/extra/miniconda3/bin/python(3.12.1)tocreatevirtualenv...Creatingvirtualenvironment...createdvirtualenvironmentCPython3.12.1.final.0-64in139mscreatorCPython3Posix(dest=/home/matteius/Envs/test_install2-DMnDbAT9,clear=False,no_vcs_ignore=False,global=False)seederFromAppData(download=False,pip=bundle,via=copy,app_data_dir=/home/matteius/.local/share/virtualenv)addedseedpackages:pip==24.0activatorsBashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivatorSuccessfullycreatedvirtualenvironment!Virtualenvlocation:/home/matteius/Envs/test_install2-DMnDbAT9CreatingaPipfileforthisproject...Installingrequests...Resolvingrequests...AddedrequeststoPipfile's[packages]...InstallationSucceededPipfile.locknotfound,creating...Locking[packages]dependencies...Buildingrequirements...Resolvingdependencies...Success!Locking[dev-packages]dependencies...UpdatedPipfile.lock(1977acb1ba9778abb66054090e2618a0a1f1759b1b3b32afd8a7d404ba18b4fb)!Toactivatethisproject'svirtualenv,runpipenvshell.Alternatively,runacommandinsidethevirtualenvwithpipenvrun.InstallingdependenciesfromPipfile.lock(18b4fb)...

Installing Pipenv

PreferredInstallationofPipenv
       It is recommended that users on most platforms install pipenv from pypi.org using

          $ pip install pipenv --user

       NOTE:pipuserinstallationsallowforinstallationintoyourhomedirectorytopreventbreakinganysystem-widepackages.Duetointeractionbetweendependencies,youshouldlimittoolsinstalledinthiswaytobasicbuildingblocksforaPythonworkflowsuchasvirtualenv,pipenv,tox,andsimilarsoftware.Ifpipenvisn’tavailableinyourshellafterinstallation,you’llneedtoaddtheusersite-packagesbinarydirectorytoyourPATH.OnLinuxandmacOSyoucanfindtheuserbasebinarydirectorybyrunningpython-msite--user-baseandappendingbintotheend.Forexample,thiswilltypicallyprint~/.local(with~expandedtotheabsolutepathtoyourhomedirectory),soyou’llneedtoadd~/.local/bintoyourPATH.YoucansetyourPATHpermanentlybymodifying~/.profile.OnWindowsyoucanfindtheuserbasebinarydirectorybyrunningpython-msite--user-siteandreplacingsite-packageswithScripts.Forexample,thiscouldreturnC:\Users\Username\AppData\Roaming\Python37\site-packages,soyouwouldneedtosetyourPATHtoincludeC:\Users\Username\AppData\Roaming\Python37\Scripts.YoucansetyouruserPATHpermanentlyintheControlPanel.YoumayneedtologoutforthePATHchangestotakeeffect.Toupgradepipenvatanytime:$pipinstall--user--upgradepipenvHomebrewInstallationofPipenvHomebrew is a popular open-source package management system for macOS (or Linux).

       Once you have installed Homebrew simply run

          $ brew install pipenv

       Toupgradepipenvatanytime:$brewupgradepipenvNOTE:
          Homebrew installation is discouraged because it works better to install pipenv using pip on macOS.

Make Sure You Have Python And Pip

       Before  you go any further, make sure you have Python and that it’s available from your command line. You
       can check this by simply running

          $ python --version

       Youshouldgetsomeoutputlike3.12.1.IfyoudonothavePython,pleaseinstallthelatest3.xversionfrompython.orgAdditionally,makesureyouhavepipavailable,assumingyouinstallviapip,ourpreferredmethodofinstallation.Checkthisbyrunning$pip--versionpip24.0IfyouinstalledPythonfromsource,withaninstallerfrompython.orgorviaHomebrew,youlikelyalreadyhavepip.Ifyou’reonLinuxandinstalledusingyourOSpackagemanager,youmayhavetoinstallpipmanually.

Name

       pipenv - Python package manager based on virtual env and Pipfiles

Synopsis

NOTE:
          This guide is written for Python 3.7+

Using Installed Packages

       Now that requests is installed you can create a simple main.py file to use it:

          import requests

          response = requests.get('https://httpbin.org/ip')
          print('Your IP is {0}'.format(response.json()['origin']))

       Thenyoucanrunthisscriptusingpipenvrun$pipenvrunpythonmain.pyYoushouldgetoutputsimilartothis:YourIPis8.8.8.8Using$pipenvrunensuresthatyourinstalledpackagesareavailabletoyourscriptbyactivatingthevirtualenv.Itisalsopossibletospawnanewshellthatensuresallcommandshaveaccesstoyourinstalledpackageswith$pipenvshell.

Virtualenv Mapping Caveat

       • Pipenv automatically maps projects to their specific virtualenvs.

       • By default, the virtualenv is stored globally with the name of the project’s root  directory  plus  the
         hash of the full path to the project’s root (e.g., my_project-a3de50).

       • Should  you  change  your project’s path, you break such a default mapping and pipenv will no longer be
         able to find and to use the project’s virtualenv.

       • If you must move or rename a directory managed by pipenv, run ‘pipenv --rm’ before renaming  or  moving
         your  project  directory. Then, after renaming or moving the directory run ‘pipenv install’ to recreate
         the virtualenv.

       • Customize this behavior with PIPENV_CUSTOM_VENV_NAME environment variable.

       • You might also prefer to set PIPENV_VENV_IN_PROJECT=1 in your .env or .bashrc/.zshrc  (or  other  shell
         configuration file) for creating the virtualenv inside your project’s directory.

See Also