Repository: pypa/pipenv

Issue:
Unable to install package in container
I was troubleshooting an opened bug (https://github.com/pypa/pipenv/issues/1639) that I seem to have run into. In trying to reproduce it, it seems like i bumped into another issue.

This looks similar to the closed https://github.com/pypa/pipenv/issues/1441 issue, however, the command `virtualenv --python=python3 myenv` did not error out as anticipated in the comments.

##### Expected result

I expected to see a `Pipfile` and `Pipfile.lock` in the `/tmp/test1` directory.

##### Actual result

Saw the strack trace above.

##### Steps to replicate

```
 saviles  ~  1  docker run --rm -ti fedora:27 /bin/bash
[root@0958ee759ab3 /]# dnf install -qy which
install-info: No such file or directory for /usr/share/info/which.info.gz
[root@0958ee759ab3 /]# pip3 install --user pipenv
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Collecting pipenv
  Downloading pipenv-11.2.0.tar.gz (4.1MB)
    100% |████████████████████████████████| 4.1MB 412kB/s 
Collecting setuptools>=36.2.1 (from pipenv)
  Downloading setuptools-38.5.2-py2.py3-none-any.whl (490kB)
    100% |████████████████████████████████| 491kB 2.3MB/s 
Collecting virtualenv (from pipenv)
  Downloading virtualenv-15.1.0-py2.py3-none-any.whl (1.8MB)
    100% |████████████████████████████████| 1.8MB 810kB/s 
Collecting virtualenv-clone>=0.2.5 (from pipenv)
  Downloading virtualenv_clone-0.3.0-py2.py3-none-any.whl
Installing collected packages: setuptools, virtualenv, virtualenv-clone, pipenv
  Running setup.py install for pipenv ... done
Successfully installed pipenv-11.2.0 setuptools-38.5.2 virtualenv-15.1.0 virtualenv-clone-0.3.0
[root@0958ee759ab3 /]# mkdir /tmp/test1
[root@0958ee759ab3 /]# cd /tmp/test1
[root@0958ee759ab3 test1]# python3 -m pipenv install requests
Warning: the environment variable LANG is not set!
We recommend setting this in ~/.profile (or equivalent) for proper expected behavior.
Creating a virtualenv for this project…
⠋Using base prefix '/usr'
New python executable in /root/.local/share/virtualenvs/test1-MiVIN7Yf/bin/python3
Also creating executable in /root/.local/share/virtualenvs/test1-MiVIN7Yf/bin/python
Installing setuptools, pip, wheel...done.

Virtualenv location: 
Creating a Pipfile for this project…
Traceback (most recent call last):
  File "/usr/lib64/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib64/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/root/.local/lib/python3.6/site-packages/pipenv/__main__.py", line 4, in <module>
    cli()
  File "/root/.local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/root/.local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/root/.local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/root/.local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/root/.local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/root/.local/lib/python3.6/site-packages/pipenv/cli.py", line 197, in install
    selective_upgrade=selective_upgrade
  File "/root/.local/lib/python3.6/site-packages/pipenv/core.py", line 1767, in do_install
    ensure_project(three=three, python=python, system=system, warn=True, deploy=deploy, skip_requirements=skip_requirements)
  File "/root/.local/lib/python3.6/site-packages/pipenv/core.py", line 688, in ensure_project
    ensure_pipfile(validate=validate, skip_requirements=skip_requirements)
  File "/root/.local/lib/python3.6/site-packages/pipenv/core.py", line 341, in ensure_pipfile
    project.create_pipfile(python=python)
  File "/root/.local/lib/python3.6/site-packages/pipenv/project.py", line 439, in create_pipfile
    data[u'requires'] = {'python_version': python_version(self.which('python'))[:len('2.7')]}
TypeError: 'NoneType' object is not subscriptable
```

[root@0958ee759ab3 test1]# python3 -m pipenv.help            
Pipenv version: `'11.2.0'`

Pipenv location: `'/root/.local/lib/python3.6/site-packages/pipenv'`

Python location: `'/usr/bin/python3'`

Other Python installations in `PATH`:

  - `3.6`: `/usr/bin/python3.6m`
  - `3.6`: `/usr/bin/python3.6`
  - `3.6`: `/bin/python3.6`

  - `3.6.2`: `/usr/bin/python3`
  - `3.6.2`: `/bin/python3`

PEP 508 Information:

```
{'implementation_name': 'cpython',
 'implementation_version': '3.6.2',
 'os_name': 'posix',
 'platform_machine': 'x86_64',
 'platform_python_implementation': 'CPython',
 'platform_release': '4.15.6-300.fc27.x86_64',
 'platform_system': 'Linux',
 'platform_version': '#1 SMP Mon Feb 26 18:43:03 UTC 2018',
 'python_full_version': '3.6.2',
 'python_version': '3.6',
 'sys_platform': 'linux'}
```

System environment variables:

  - `LS_COLORS`
  - `HOSTNAME`
  - `PWD`
  - `HOME`
  - `FBR`
  - `DISTTAG`
  - `FGC`
  - `TERM`
  - `SHLVL`
  - `PATH`
  - `_`
  - `OLDPWD`
  - `LC_CTYPE`
  - `PIP_PYTHON_PATH`

Pipenv–specific environment variables:


Debug–specific environment variables:

  - `PATH`: `/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin`
  - `PWD`: `/tmp/test1`


---------------------------

Contents of `Pipfile` ('/tmp/test1/Pipfile'):

```toml

```
```
[root@0958ee759ab3 test1]# envname
bash: envname: command not found
[root@0958ee759ab3 test1]# virtualenv --python=python3 myenv
bash: virtualenv: command not found
[root@0958ee759ab3 test1]# python3 -m virtualenv --python=python3 myenv
Already using interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /tmp/test1/myenv/bin/python3
Also creating executable in /tmp/test1/myenv/bin/python
Installing setuptools, pip, wheel...done.
[root@0958ee759ab3 test1]# ls
Pipfile  myenv
[root@0958ee759ab3 test1]# 
```
(Edit: Formatting)


Discussion:
Yes! We've been seeing this, but haven't been able to reproduce reliably. Good work!
Here's another manifestation:
```
$ docker run --rm -it python:latest bash
root@a8acc994176d:/# cd
root@a8acc994176d:~# pip install --user pipenv
Collecting pipenv
  Downloading pipenv-11.2.0.tar.gz (4.1MB)
    100% |████████████████████████████████| 4.1MB 322kB/s 
Requirement already satisfied: setuptools>=36.2.1 in /usr/local/lib/python3.6/site-packages (from pipenv)
Collecting virtualenv (from pipenv)
  Downloading virtualenv-15.1.0-py2.py3-none-any.whl (1.8MB)
    100% |████████████████████████████████| 1.8MB 595kB/s 
Collecting virtualenv-clone>=0.2.5 (from pipenv)
  Downloading virtualenv_clone-0.3.0-py2.py3-none-any.whl
Building wheels for collected packages: pipenv
  Running setup.py bdist_wheel for pipenv ... done
  Stored in directory: /root/.cache/pip/wheels/21/58/1f/05230cc8f245b4ae4b90338c86c6531ea0629d7717b0b13c8d
Successfully built pipenv
Installing collected packages: virtualenv, virtualenv-clone, pipenv
Successfully installed pipenv-11.2.0 virtualenv-15.1.0 virtualenv-clone-0.3.0
root@a8acc994176d:~# git clone https://github.com/maxalbert/pipenv_bug.git
Cloning into 'pipenv_bug'...
remote: Counting objects: 68, done.
remote: Compressing objects: 100% (39/39), done.
remote: Total 68 (delta 18), reused 65 (delta 15), pack-reused 0
Unpacking objects: 100% (68/68), done.
Checking connectivity... done.
root@a8acc994176d:~# cd pipenv_bug/
root@a8acc994176d:~/pipenv_bug# rm Pipfile.lock 
root@a8acc994176d:~/pipenv_bug# pipenv install
bash: pipenv: command not found
root@a8acc994176d:~/pipenv_bug# ~/.local/bin/pipenv install
Creating a virtualenv for this project…
Using /usr/local/bin/python3.6m to create virtualenv…
⠋Running virtualenv with interpreter /usr/local/bin/python3.6m
Using base prefix '/usr/local'
New python executable in /root/.local/share/virtualenvs/pipenv_bug-YVUDmhpZ/bin/python3.6m
Also creating executable in /root/.local/share/virtualenvs/pipenv_bug-YVUDmhpZ/bin/python
Installing setuptools, pip, wheel...done.

Virtualenv location: 
Warning: Your Pipfile requires python_version 3.6, but you are using None (/bin/python).
  $ pipenv check will surely fail.
Creating a virtualenv for this project…
⠙Using base prefix '/usr/local'
New python executable in /root/.local/share/virtualenvs/pipenv_bug-YVUDmhpZ/bin/python
Installing setuptools, pip, wheel...done.

Virtualenv location: 
Pipfile.lock not found, creating…
Locking [dev-packages] dependencies…
/python: not found

root@a8acc994176d:~/pipenv_bug# ~/.local/bin/pipenv run pytest --version
Creating a virtualenv for this project…
Using /usr/local/bin/python3.6m to create virtualenv…
⠋Running virtualenv with interpreter /usr/local/bin/python3.6m
Using base prefix '/usr/local'
New python executable in /root/.local/share/virtualenvs/pipenv_bug-YVUDmhpZ/bin/python3.6m
Not overwriting existing python script /root/.local/share/virtualenvs/pipenv_bug-YVUDmhpZ/bin/python (you must use /root/.local/share/virtualenvs/pipenv_bug-YVUDmhpZ/bin/python3.6m)
Installing setuptools, pip, wheel...done.

Virtualenv location: 
Warning: Your Pipfile requires python_version 3.6, but you are using None (/bin/python).
  $ pipenv check will surely fail.
Warning: There was an unexpected error while activating your virtualenv. Continuing anyway…
Error: the command pytest could not be found within PATH or Pipfile's [scripts].
```

Namely,
> Warning: Your Pipfile requires python_version 3.6, but you are using None (/bin/python).
Well, i know one way to solve this.
Don't use Docker? :)
I got past the initial error hacking this:
```
diff --git a/pipenv/project.py b/pipenv/project.py
index 64577fd..029e94f 100644
--- a/pipenv/project.py
+++ b/pipenv/project.py
@@ -436,7 +436,7 @@ class Project(object):
         }
 
         # Default requires.
-        data[u'requires'] = {'python_version': python_version(self.which('python'))[:len('2.7')]}
+        data[u'requires'] = {'python_version': python_version(self.which('python3'))[:len('3.')]}
 
         self.write_toml(data, 'Pipfile')
```

Now i'm trying to bypass the next hurdle
```
[root@0958ee759ab3 test1]# python3 -m pipenv --venv
No virtualenv has been created for this project yet!
[root@0958ee759ab3 test1]# ls /root/.local/share/virtualenvs/test1-MiVIN7Yf/bin/python
/root/.local/share/virtualenvs/test1-MiVIN7Yf/bin/python
[root@0958ee759ab3 test1]# rm -rf /root/.local/share/virtualenvs/test1-MiVIN7Yf           
[root@0958ee759ab3 test1]# python3 -m pipenv install requests
Warning: the environment variable LANG is not set!
We recommend setting this in ~/.profile (or equivalent) for proper expected behavior.
Creating a virtualenv for this project…
⠋Using base prefix '/usr'
New python executable in /root/.local/share/virtualenvs/test1-MiVIN7Yf/bin/python3
Also creating executable in /root/.local/share/virtualenvs/test1-MiVIN7Yf/bin/python
Installing setuptools, pip, wheel...done.

Virtualenv location: 
Installing requests…
⠙
Error:  An error occurred while installing requests!
/bin/sh: /bin/pip: No such file or directory

[root@0958ee759ab3 test1]# /root/.local/share/virtualenvs/test1-MiVIN7Yf/bin/python3 --version
Python 3.6.2
[root@0958ee759ab3 test1]# /root/.local/share/virtualenvs/test1-MiVIN7Yf/bin/python --version
Python 3.6.2
[root@0958ee759ab3 test1]# 
```

My suspicion is that there assumptions that `python` and `pip` will be available but that may not be necessarily the case.
can you try again with the latest version?
pip and virtualenv should always be available within a virtualenv, yes. 
I'm still repro-ing on 11.2.2:
```
$ docker run --rm -it python:latest bash
root@6931fdb72b42:/# cd
root@6931fdb72b42:~# pip install --user pipenv
Collecting pipenv
  Downloading pipenv-11.2.2.tar.gz (4.1MB)
    100% |████████████████████████████████| 4.1MB 294kB/s 
Requirement already satisfied: setuptools>=36.2.1 in /usr/local/lib/python3.6/site-packages (from pipenv)
Collecting virtualenv (from pipenv)
  Downloading virtualenv-15.1.0-py2.py3-none-any.whl (1.8MB)
    100% |████████████████████████████████| 1.8MB 716kB/s 
Collecting virtualenv-clone>=0.2.5 (from pipenv)
  Downloading virtualenv_clone-0.3.0-py2.py3-none-any.whl
Building wheels for collected packages: pipenv
  Running setup.py bdist_wheel for pipenv ... done
  Stored in directory: /root/.cache/pip/wheels/0c/05/ea/2c54795c34f7c6da5ea0e8013fa6dbd9efed88f02304d10eb1
Successfully built pipenv
Installing collected packages: virtualenv, virtualenv-clone, pipenv
Successfully installed pipenv-11.2.2 virtualenv-15.1.0 virtualenv-clone-0.3.0
root@6931fdb72b42:~# git clone https://github.com/maxalbert/pipenv_bug.git
Cloning into 'pipenv_bug'...
remote: Counting objects: 68, done.
remote: Compressing objects: 100% (39/39), done.
remote: Total 68 (delta 18), reused 65 (delta 15), pack-reused 0
Unpacking objects: 100% (68/68), done.
Checking connectivity... done.
root@6931fdb72b42:~# cd pipenv_bug/
root@6931fdb72b42:~/pipenv_bug# ls -l
total 8
-rw-r--r-- 1 root root  153 Mar 10 01:59 Pipfile
-rw-r--r-- 1 root root 1787 Mar 10 01:59 Pipfile.lock
root@6931fdb72b42:~/pipenv_bug# rm Pipfile.lock
root@6931fdb72b42:~/pipenv_bug# pipenv install
bash: pipenv: command not found
root@6931fdb72b42:~/pipenv_bug# ~/.local/bin/pipenv install
Creating a virtualenv for this project…
Using /usr/local/bin/python3.6m to create virtualenv…
⠋Running virtualenv with interpreter /usr/local/bin/python3.6m
Using base prefix '/usr/local'
New python executable in /root/.local/share/virtualenvs/pipenv_bug-YVUDmhpZ/bin/python3.6m
Also creating executable in /root/.local/share/virtualenvs/pipenv_bug-YVUDmhpZ/bin/python
Installing setuptools, pip, wheel...done.

Virtualenv location: 
Warning: Your Pipfile requires python_version 3.6, but you are using None (/bin/python).
  $ pipenv check will surely fail.
Creating a virtualenv for this project…
⠙Using base prefix '/usr/local'
New python executable in /root/.local/share/virtualenvs/pipenv_bug-YVUDmhpZ/bin/python
Installing setuptools, pip, wheel...done.

Virtualenv location: 
Pipfile.lock not found, creating…
Locking [dev-packages] dependencies…
/python: not found

```
Why is “virtualenv location” empty?

Sent from my iPhone

> On Mar 9, 2018, at 9:00 PM, David Tucker <notifications@github.com> wrote:
> 
> I'm still repro-ing on 11.2.2:
> 
> $ docker run --rm -it python:latest bash
> root@6931fdb72b42:/# cd
> root@6931fdb72b42:~# pip install --user pipenv
> Collecting pipenv
>   Downloading pipenv-11.2.2.tar.gz (4.1MB)
>     100% |████████████████████████████████| 4.1MB 294kB/s 
> Requirement already satisfied: setuptools>=36.2.1 in /usr/local/lib/python3.6/site-packages (from pipenv)
> Collecting virtualenv (from pipenv)
>   Downloading virtualenv-15.1.0-py2.py3-none-any.whl (1.8MB)
>     100% |████████████████████████████████| 1.8MB 716kB/s 
> Collecting virtualenv-clone>=0.2.5 (from pipenv)
>   Downloading virtualenv_clone-0.3.0-py2.py3-none-any.whl
> Building wheels for collected packages: pipenv
>   Running setup.py bdist_wheel for pipenv ... done
>   Stored in directory: /root/.cache/pip/wheels/0c/05/ea/2c54795c34f7c6da5ea0e8013fa6dbd9efed88f02304d10eb1
> Successfully built pipenv
> Installing collected packages: virtualenv, virtualenv-clone, pipenv
> Successfully installed pipenv-11.2.2 virtualenv-15.1.0 virtualenv-clone-0.3.0
> root@6931fdb72b42:~# git clone https://github.com/maxalbert/pipenv_bug.git
> Cloning into 'pipenv_bug'...
> remote: Counting objects: 68, done.
> remote: Compressing objects: 100% (39/39), done.
> remote: Total 68 (delta 18), reused 65 (delta 15), pack-reused 0
> Unpacking objects: 100% (68/68), done.
> Checking connectivity... done.
> root@6931fdb72b42:~# cd pipenv_bug/
> root@6931fdb72b42:~/pipenv_bug# ls -l
> total 8
> -rw-r--r-- 1 root root  153 Mar 10 01:59 Pipfile
> -rw-r--r-- 1 root root 1787 Mar 10 01:59 Pipfile.lock
> root@6931fdb72b42:~/pipenv_bug# rm Pipfile.lock
> root@6931fdb72b42:~/pipenv_bug# pipenv install
> bash: pipenv: command not found
> root@6931fdb72b42:~/pipenv_bug# ~/.local/bin/pipenv install
> Creating a virtualenv for this project…
> Using /usr/local/bin/python3.6m to create virtualenv…
> ⠋Running virtualenv with interpreter /usr/local/bin/python3.6m
> Using base prefix '/usr/local'
> New python executable in /root/.local/share/virtualenvs/pipenv_bug-YVUDmhpZ/bin/python3.6m
> Also creating executable in /root/.local/share/virtualenvs/pipenv_bug-YVUDmhpZ/bin/python
> Installing setuptools, pip, wheel...done.
> 
> Virtualenv location: 
> Warning: Your Pipfile requires python_version 3.6, but you are using None (/bin/python).
>   $ pipenv check will surely fail.
> Creating a virtualenv for this project…
> ⠙Using base prefix '/usr/local'
> New python executable in /root/.local/share/virtualenvs/pipenv_bug-YVUDmhpZ/bin/python
> Installing setuptools, pip, wheel...done.
> 
> Virtualenv location: 
> Pipfile.lock not found, creating…
> Locking [dev-packages] dependencies…
> /python: not found
> 
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub, or mute the thread.
> 

That’s the bug

Sent from my iPhone

> On Mar 9, 2018, at 9:00 PM, David Tucker <notifications@github.com> wrote:
> 
> I'm still repro-ing on 11.2.2:
> 
> $ docker run --rm -it python:latest bash
> root@6931fdb72b42:/# cd
> root@6931fdb72b42:~# pip install --user pipenv
> Collecting pipenv
>   Downloading pipenv-11.2.2.tar.gz (4.1MB)
>     100% |████████████████████████████████| 4.1MB 294kB/s 
> Requirement already satisfied: setuptools>=36.2.1 in /usr/local/lib/python3.6/site-packages (from pipenv)
> Collecting virtualenv (from pipenv)
>   Downloading virtualenv-15.1.0-py2.py3-none-any.whl (1.8MB)
>     100% |████████████████████████████████| 1.8MB 716kB/s 
> Collecting virtualenv-clone>=0.2.5 (from pipenv)
>   Downloading virtualenv_clone-0.3.0-py2.py3-none-any.whl
> Building wheels for collected packages: pipenv
>   Running setup.py bdist_wheel for pipenv ... done
>   Stored in directory: /root/.cache/pip/wheels/0c/05/ea/2c54795c34f7c6da5ea0e8013fa6dbd9efed88f02304d10eb1
> Successfully built pipenv
> Installing collected packages: virtualenv, virtualenv-clone, pipenv
> Successfully installed pipenv-11.2.2 virtualenv-15.1.0 virtualenv-clone-0.3.0
> root@6931fdb72b42:~# git clone https://github.com/maxalbert/pipenv_bug.git
> Cloning into 'pipenv_bug'...
> remote: Counting objects: 68, done.
> remote: Compressing objects: 100% (39/39), done.
> remote: Total 68 (delta 18), reused 65 (delta 15), pack-reused 0
> Unpacking objects: 100% (68/68), done.
> Checking connectivity... done.
> root@6931fdb72b42:~# cd pipenv_bug/
> root@6931fdb72b42:~/pipenv_bug# ls -l
> total 8
> -rw-r--r-- 1 root root  153 Mar 10 01:59 Pipfile
> -rw-r--r-- 1 root root 1787 Mar 10 01:59 Pipfile.lock
> root@6931fdb72b42:~/pipenv_bug# rm Pipfile.lock
> root@6931fdb72b42:~/pipenv_bug# pipenv install
> bash: pipenv: command not found
> root@6931fdb72b42:~/pipenv_bug# ~/.local/bin/pipenv install
> Creating a virtualenv for this project…
> Using /usr/local/bin/python3.6m to create virtualenv…
> ⠋Running virtualenv with interpreter /usr/local/bin/python3.6m
> Using base prefix '/usr/local'
> New python executable in /root/.local/share/virtualenvs/pipenv_bug-YVUDmhpZ/bin/python3.6m
> Also creating executable in /root/.local/share/virtualenvs/pipenv_bug-YVUDmhpZ/bin/python
> Installing setuptools, pip, wheel...done.
> 
> Virtualenv location: 
> Warning: Your Pipfile requires python_version 3.6, but you are using None (/bin/python).
>   $ pipenv check will surely fail.
> Creating a virtualenv for this project…
> ⠙Using base prefix '/usr/local'
> New python executable in /root/.local/share/virtualenvs/pipenv_bug-YVUDmhpZ/bin/python
> Installing setuptools, pip, wheel...done.
> 
> Virtualenv location: 
> Pipfile.lock not found, creating…
> Locking [dev-packages] dependencies…
> /python: not found
> 
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub, or mute the thread.
> 


Resolving patch:
diff --git a/pipenv/core.py b/pipenv/core.py
--- a/pipenv/core.py
+++ b/pipenv/core.py
@@ -975,17 +975,16 @@ def do_create_virtualenv(python=None, site_packages=False):
         # Default: use pew.
         cmd = [sys.executable, '-m', 'pipenv.pew', 'new', project.virtualenv_name, '-d']
 
-    # Pass a Python version to virtualenv, if needed.
-    if python:
-        click.echo(u'{0} {1} {2}'.format(
-            crayons.normal('Using', bold=True),
-            crayons.red(python, bold=True),
-            crayons.normal(u'to create virtualenv…', bold=True)
-        ), err=True)
+    if not python:
+        python = find_a_system_python('3.6') or find_a_system_python('3') or sys.executable
 
-    # Use virtualenv's -p python.
-    if python:
-        cmd = cmd + ['-p', python]
+    click.echo(u'{0} {1} {2}'.format(
+        crayons.normal('Using', bold=True),
+        crayons.red(python, bold=True),
+        crayons.normal(u'to create virtualenv…', bold=True)
+    ), err=True)
+
+    cmd = cmd + ['-p', python]
 
     # Actually create the virtualenv.
     with spinner():
diff --git a/pipenv/project.py b/pipenv/project.py
--- a/pipenv/project.py
+++ b/pipenv/project.py
@@ -436,7 +436,8 @@ def create_pipfile(self, python=None):
         }
 
         # Default requires.
-        data[u'requires'] = {'python_version': python_version(self.which('python'))[:len('2.7')]}
+        required_python = python if python else self.which('python', self.virtualenv_location)
+        data[u'requires'] = {'python_version': python_version(required_python)[:len('2.7')]}
 
         self.write_toml(data, 'Pipfile')
 


Test patch: