Repository: pypa/pipenv

Issue:
How to install prerelease version using pipenv?
I tried installing Django prelease using pipenv, here are the steps I followed

- `pipenv lock --pre`

-  `pipenv install --pre Django`

And when I check the `pip freeze` it shows me correct version of the Django

```
(fiobot-dPUFI04r) simon@ENGINE:~/Nightybuild/fiobot$ pip freeze
Django==2.0b1
gunicorn==19.7.1
pytz==2017.2
``` 

However when I looked into Pipfile.lock it shows this  `"version": "==1.11.6"` 

**I deployed to Heroku my code doesn't run because my code needs pre release version of Django how to  solve this ?**

##### My environment

1. OS Type: Ubuntu 16.04 LTS
1. Python version: `Python 3.6.3`
1. Pipenv version: `pipenv, version 8.2.7`



Discussion:
A couple of things:

1. Please provide your pipfile
2. You shouldn’t run pipenv from inside it’s own shell. It won’t work. 
3. You can’t lock things before you install them, the workflow is the other way around
4. Installing things implicitly locks them so you shouldn’t need to run lock right after an install 

So you will need to exit the subshell, and start over. If you want a specific pinned release of Django you should install that explicitly as well, but if you want to allow prereleases all you need to do is run: `pipenv install —pre`
Oh here is my `Pipfile`. And I can't mention the exact version of Django in package because that's not working. 

```
[[source]]

url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"


[dev-packages]



[packages]

django = "*"
gunicorn = "*"


[requires]

python_version = "3.6"


[pipenv]

allow_prereleases = true
```
So I just installed Django with the --pre flag,  It works as expected.  In my `Pipfile.lock` I have the following entry for Django.

```
"django": {
    "hashes": [
        "sha256:5e7f0d33a1908070d81ffea029c7c69f7b8aa9c95fa2415885ea3c970c2cf8e0"
    ],
    "version": "==2.0b1"
}
```
It looks like the beta version of Django 2 is installed.  If your code isn't working is it possible it relies on an alpha that isn't in pypi?

I'm just checking around the Django 2.0. I can't believe it's worked for you. I think it happens because of my machine even though I clear cache and everything still not works. Is it possible to use that hashes value in my project to install the pre release of Django ?
can you lock your Pipfile and post it?
You mean my Pipfile.lock or Pipfile ?


This is my Pipfile
```
[[source]]

url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"


[dev-packages]



[packages]

gunicorn = "*"
django = "*"


[requires]

python_version = "3.6"


[pipenv]

allow_prereleases = true

```

Pipfile.lock

```
{
    "_meta": {
        "hash": {
            "sha256": "0f9748b3cc9cd1a17d1640c919a06ab04bae217b3cca2199271ba34d3948d763"
        },
        "host-environment-markers": {
            "implementation_name": "cpython",
            "implementation_version": "3.6.1",
            "os_name": "posix",
            "platform_machine": "x86_64",
            "platform_python_implementation": "CPython",
            "platform_release": "17.0.0",
            "platform_system": "Darwin",
            "platform_version": "Darwin Kernel Version 17.0.0: Thu Aug 24 21:48:19 PDT 2017; root:xnu-4570.1.46~2/RELEASE_X86_64",
            "python_full_version": "3.6.1",
            "python_version": "3.6",
            "sys_platform": "darwin"
        },
        "pipfile-spec": 6,
        "requires": {
            "python_version": "3.6"
        },
        "sources": [
            {
                "name": "pypi",
                "url": "https://pypi.python.org/simple",
                "verify_ssl": true
            }
        ]
    },
    "default": {
        "django": {
            "hashes": [
                "sha256:7ab6a9c798a5f9f359ee6da3677211f883fb02ef32cebe9b29751eb7a871febf",
                "sha256:c3b42ca1efa1c0a129a9e863134cc3fe705c651dea3a04a7998019e522af0c60"
            ],
            "version": "==1.11.6"
        },
        "gunicorn": {
            "hashes": [
                "sha256:75af03c99389535f218cc596c7de74df4763803f7b63eb09d77e92b3956b36c6",
                "sha256:eee1169f0ca667be05db3351a0960765620dad53f53434262ff8901b68a1b622"
            ],
            "version": "==19.7.1"
        },
        "pytz": {
            "hashes": [
                "sha256:c883c2d6670042c7bc1688645cac73dd2b03193d1f7a6847b6154e96890be06d",
                "sha256:03c9962afe00e503e2d96abab4e8998a0f84d4230fa57afe1e0528473698cdd9",
                "sha256:487e7d50710661116325747a9cd1744d3323f8e49748e287bc9e659060ec6bf9",
                "sha256:43f52d4c6a0be301d53ebd867de05e2926c35728b3260157d274635a0a947f1c",
                "sha256:d1d6729c85acea5423671382868627129432fba9a89ecbb248d8d1c7a9f01c67",
                "sha256:54a935085f7bf101f86b2aff75bd9672b435f51c3339db2ff616e66845f2b8f9",
                "sha256:39504670abb5dae77f56f8eb63823937ce727d7cdd0088e6909e6dcac0f89043",
                "sha256:ddc93b6d41cfb81266a27d23a79e13805d4a5521032b512643af8729041a81b4",
                "sha256:f5c056e8f62d45ba8215e5cb8f50dfccb198b4b9fbea8500674f3443e4689589"
            ],
            "version": "==2017.2"
        }
    },
    "develop": {}
}
```
It looks like the allow_prerelease environment marker isn't respected when you do `pipenv lock`.  You have to do `pipenv lock --pre` or `pipenv install --pre django` for now.  `pipenv install` relocks the file by default so it uses the --pre flag.  For now you'll have to use either of those two methods until we get the bug fixed!

Resolving patch:
diff --git a/pipenv/cli.py b/pipenv/cli.py
--- a/pipenv/cli.py
+++ b/pipenv/cli.py
@@ -1238,7 +1238,7 @@ def do_purge(bare=False, downloads=False, allow_global=False, verbose=False):
 
 def do_init(
     dev=False, requirements=False, allow_global=False, ignore_pipfile=False,
-    skip_lock=False, verbose=False, system=False, concurrent=True, deploy=False
+    skip_lock=False, verbose=False, system=False, concurrent=True, deploy=False, pre=False
 ):
     """Executes the init functionality."""
 
@@ -1290,12 +1290,12 @@ def do_init(
                     err=True
                 )
 
-                do_lock(system=system)
+                do_lock(system=system, pre=pre)
 
     # Write out the lockfile if it doesn't exist.
     if not project.lockfile_exists and not skip_lock:
         click.echo(crayons.normal(u'Pipfile.lock not found, creating…', bold=True), err=True)
-        do_lock(system=system)
+        do_lock(system=system, pre=pre)
 
     do_install_dependencies(dev=dev, requirements=requirements, allow_global=allow_global,
                             skip_lock=skip_lock, verbose=verbose, concurrent=concurrent)
@@ -1312,6 +1312,7 @@ def pip_install(
 
     if verbose:
         click.echo(crayons.normal('Installing {0!r}'.format(package_name), bold=True), err=True)
+    # print(pre)
 
     # Create files for hash mode.
     if (not ignore_hashes) and (r is None):
@@ -1825,13 +1826,12 @@ def install(
 
     # Install all dependencies, if none was provided.
     if package_name is False:
-
-        do_init(dev=dev, allow_global=system, ignore_pipfile=ignore_pipfile, system=system, skip_lock=skip_lock, verbose=verbose, concurrent=concurrent, deploy=deploy)
-
         # Update project settings with pre preference.
         if pre:
             project.update_settings({'allow_prereleases': pre})
 
+        do_init(dev=dev, allow_global=system, ignore_pipfile=ignore_pipfile, system=system, skip_lock=skip_lock, verbose=verbose, concurrent=concurrent, deploy=deploy, pre=pre)
+
         sys.exit(0)
 
     for package_name in package_names:
@@ -1839,6 +1839,7 @@ def install(
 
         # pip install:
         with spinner():
+
             c = pip_install(package_name, ignore_hashes=True, allow_global=system, no_deps=False, verbose=verbose, pre=pre)
 
             # Warn if --editable wasn't passed.


Test patch: