Python Forum

Full Version: Pipenv
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pipenv is now the official recommended Python packaging tool from Python.org.
The documentation look at this video for usage.

I did test it in a earlier stage then it did not work for Windows,
now is all OS supported.

Here a test and usage of Pipenv with Windows.
pip install -U pipenv
# make a folder
E:\1
λ mkdir web_title

# cd in
E:\1
λ cd web_title
E:\1\web_title

# Activate shell
λ pipenv shell
Creating a Pipfile for this project...
Creating a virtualenv for this project...
Using base prefix 'c:\\python36'
....
Installing setuptools, pip, wheel...done.
At this point this empty folder is a virtual environment.
Can look a Python and pip placement.
E:\1\web_title
λ pipenv --venv
C:\Users\Tom\.virtualenvs\web_title-vYANOqhT

 E:\1\web_title
λ which python
/c/Users/Tom/.virtualenvs/web_title-vYANOqhT/Scripts/python

E:\1\web_title
λ pip -V
pip 9.0.1 from c:\users\tom\.virtualenvs\web_title-vyanoqht\lib\site-packages (python 3.6)
Place a file in this folder.
# find_title.py
import requests
from bs4 import BeautifulSoup

def web_title(url):
    '''find web site title'''
    url_get = requests.get(url)
    soup = BeautifulSoup(url_get.content, 'lxml')
    print(soup.select('head > title')[0].text)

if __name__ == '__main__':
    #url = 'http://CNN.com'
    url = 'https://www.python.org/'
    web_title(url)
Try to run the file.
E:\1\web_title
λ python find_title.py
Traceback (most recent call last):
  File "find_title.py", line 2, in <module>
    import requests
ModuleNotFoundError: No module named 'requests'
Pipenv works like pip,so need to install Requests,BeautifulSoup and lxml.
E:\1\web_title
λ pipenv install beautifulsoup4 requests lxml

# Run again
E:\1\web_title
λ python find_title.py
Welcome to Python.org
Look at dependencies with graph command.
E:\1\web_title
λ pipenv graph
beautifulsoup4==4.6.0
lxml==3.8.0
pip==9.0.1
requests==2.18.4
  - certifi [required: >=2017.4.17, installed: 2017.7.27.1]
  - chardet [required: <3.1.0,>=3.0.2, installed: 3.0.4]
  - idna [required: >=2.5,<2.7, installed: 2.6]
  - urllib3 [required: <1.23,>=1.21.1, installed: 1.22]
setuptools==36.4.0
wheel==0.30.0
So all work,to get out shell modus(virtualenv) type exit.

If want run in a editor is the same way as with virtual environment.
Point to Python version used in environment.
I use VS code,so there is a setting.json file where i can select workspace interpreter.
{
"python.pythonPath": "C:\Users\Tom\.virtualenvs\web_title-vYANOqhT\python.exe"
}
[Image: HBSXCv.jpg]
(Sep-11-2017, 05:12 PM)snippsat Wrote: [ -> ]If want run in a editor is the same way as with virtual environment.
Point to Python version used in environment.
I use VS code,so there is a setting.json file where i can select workspace interpreter.

That'd use the same interpreter as the virtual env, but it wouldn't use the same environment. So if you run your stuff through vs code, it'd use the global pip modules.
Yes you are right,
i have to set interpreter in Code runner user setting if i use that to run.
"php": "php",
"python": "C:\\Users\\Tom\\.virtualenvs\\web_title-vYANOqhT\\Scripts\\python.exe",
"perl": "perl",
Usually i just run from integrated terminal with activated shell.
It looks like maybe you can use something like pipenv run python to start up the interpreter within the right environment: http://docs.pipenv.org/en/latest/#pipenv-run
Yes i think that would work fine.
I have not used Pipenv so much yet,
so will for sure try to use it more now that it's stable and work for all OS.
While trying to install wxpython using pipenv, got the following error message:

Error:
File "c:\python36\lib\site-packages\piptools\resolver.py", line 131, in check_constraints     raise UnsupportedConstraint(msg, constraint) piptools.exceptions.UnsupportedConstraint: pip-compile does not support URLs as packages, unless they are editable. Perhaps add -e option? (constraint was: wxpython==4.0.0b1 from file:///M:/python/q-t/r/RfcViewer_1_1_0/wxpython-4.0.0b1-cp36-cp36m-win-amd64.whl)
The package appears to be installed, but I'm concerned that something is missing.
Tried -e option ( pipenv install -e wxpython) and got:
Installing -e wxpython...

Error:  An error occurred while installing -e wxpython!
Error:
wxpython should either be a path to a local project or a VCS url beginning with svn+, git+, hg+, or bzr+
Not sure I'm Ok, haven't got that warm fuzzy feeling!

What do you think?
(Sep-12-2017, 10:01 PM)Larz60+ Wrote: [ -> ]What do you think?
Try again after update  pip install -U pipenv

It's been updated 5-6 times after i post,so a lot of development is going on.
One of the newest feature.
Automatic Python Installation 
So can call pyenv if installed,to do automatic installation of Python.
Thanks, I'll give it a go
I had that error earlier with wxpython,newest version is gone.
Great, I love this concept, and want to use it going forward!