Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pip install error ModuleNotFoundError: No module named 'pystan' #401

Closed
msoedov opened this issue Jan 3, 2018 · 44 comments
Closed

Pip install error ModuleNotFoundError: No module named 'pystan' #401

msoedov opened this issue Jan 3, 2018 · 44 comments

Comments

@msoedov
Copy link

msoedov commented Jan 3, 2018

pip --version
pip 9.0.1 from /Users/miasool/pyenvs/xor_ai/lib/python3.6/site-packages (python 3.6)
pip install fbprophet
Collecting fbprophet
  Downloading fbprophet-0.2.1.tar.gz
Requirement already satisfied: matplotlib in /Users/miasool/pyenvs/xor_ai/lib/python3.6/site-packages (from fbprophet)
Requirement already satisfied: pandas>=0.18.1 in /Users/miasool/pyenvs/xor_ai/lib/python3.6/site-packages (from fbprophet)
Collecting pystan>=2.14 (from fbprophet)
  Downloading pystan-2.17.0.0-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (35.2MB)
    100% |████████████████████████████████| 35.2MB 43kB/s
Requirement already satisfied: python-dateutil>=2.0 in /Users/miasool/pyenvs/xor_ai/lib/python3.6/site-packages (from matplotlib->fbprophet)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /Users/miasool/pyenvs/xor_ai/lib/python3.6/site-packages (from matplotlib->fbprophet)
Requirement already satisfied: cycler>=0.10 in /Users/miasool/pyenvs/xor_ai/lib/python3.6/site-packages (from matplotlib->fbprophet)
Requirement already satisfied: numpy>=1.7.1 in /Users/miasool/pyenvs/xor_ai/lib/python3.6/site-packages (from matplotlib->fbprophet)
Requirement already satisfied: six>=1.10 in /Users/miasool/pyenvs/xor_ai/lib/python3.6/site-packages (from matplotlib->fbprophet)
Requirement already satisfied: pytz in /Users/miasool/pyenvs/xor_ai/lib/python3.6/site-packages (from matplotlib->fbprophet)
Collecting Cython!=0.25.1,>=0.22 (from pystan>=2.14->fbprophet)
  Downloading Cython-0.27.3-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (4.7MB)
    100% |████████████████████████████████| 4.7MB 290kB/s
Building wheels for collected packages: fbprophet
  Running setup.py bdist_wheel for fbprophet ... error
  Complete output from command /Users/miasool/pyenvs/xor_ai/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/private/var/folders/c0/mz0pnjn131d5rsl43kr5my6xh2lw2t/T/pip-build-19fj5puw/fbprophet/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /var/folders/c0/mz0pnjn131d5rsl43kr5my6xh2lw2t/T/tmpe7pukz0npip-wheel- --python-tag cp36:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib
  creating build/lib/fbprophet
  creating build/lib/fbprophet/stan_models
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/private/var/folders/c0/mz0pnjn131d5rsl43kr5my6xh2lw2t/T/pip-build-19fj5puw/fbprophet/setup.py", line 126, in <module>
      """
    File "/Users/miasool/pyenvs/xor_ai/lib/python3.6/site-packages/setuptools/__init__.py", line 129, in setup
      return distutils.core.setup(**attrs)
    File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/core.py", line 148, in setup
      dist.run_commands()
    File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/dist.py", line 955, in run_commands
      self.run_command(cmd)
    File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/dist.py", line 974, in run_command
      cmd_obj.run()
    File "/Users/miasool/pyenvs/xor_ai/lib/python3.6/site-packages/wheel/bdist_wheel.py", line 204, in run
      self.run_command('build')
    File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/dist.py", line 974, in run_command
      cmd_obj.run()
    File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/command/build.py", line 135, in run
      self.run_command(cmd_name)
    File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/dist.py", line 974, in run_command
      cmd_obj.run()
    File "/private/var/folders/c0/mz0pnjn131d5rsl43kr5my6xh2lw2t/T/pip-build-19fj5puw/fbprophet/setup.py", line 46, in run
      build_stan_models(target_dir)
    File "/private/var/folders/c0/mz0pnjn131d5rsl43kr5my6xh2lw2t/T/pip-build-19fj5puw/fbprophet/setup.py", line 28, in build_stan_models
      from pystan import StanModel
  ModuleNotFoundError: No module named 'pystan'

  ----------------------------------------
  Failed building wheel for fbprophet
  Running setup.py clean for fbprophet
Failed to build fbprophet
Installing collected packages: Cython, pystan, fbprophet
  Running setup.py install for fbprophet ... done
Successfully installed Cython-0.27.3 fbprophet-0.2.1 pystan-2.17.0.0

However with the second run it showed no error

pip install fbprophet
Requirement already satisfied: fbprophet in /Users/miasool/pyenvs/xor_ai/lib/python3.6/site-packages
Requirement already satisfied: matplotlib in /Users/miasool/pyenvs/xor_ai/lib/python3.6/site-packages (from fbprophet)
Requirement already satisfied: pandas>=0.18.1 in /Users/miasool/pyenvs/xor_ai/lib/python3.6/site-packages (from fbprophet)
Requirement already satisfied: pystan>=2.14 in /Users/miasool/pyenvs/xor_ai/lib/python3.6/site-packages (from fbprophet)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /Users/miasool/pyenvs/xor_ai/lib/python3.6/site-packages (from matplotlib->fbprophet)
Requirement already satisfied: numpy>=1.7.1 in /Users/miasool/pyenvs/xor_ai/lib/python3.6/site-packages (from matplotlib->fbprophet)
Requirement already satisfied: six>=1.10 in /Users/miasool/pyenvs/xor_ai/lib/python3.6/site-packages (from matplotlib->fbprophet)
Requirement already satisfied: cycler>=0.10 in /Users/miasool/pyenvs/xor_ai/lib/python3.6/site-packages (from matplotlib->fbprophet)
Requirement already satisfied: pytz in /Users/miasool/pyenvs/xor_ai/lib/python3.6/site-packages (from matplotlib->fbprophet)
Requirement already satisfied: python-dateutil>=2.0 in /Users/miasool/pyenvs/xor_ai/lib/python3.6/site-packages (from matplotlib->fbprophet)
Requirement already satisfied: Cython!=0.25.1,>=0.22 in /Users/miasool/pyenvs/xor_ai/lib/python3.6/site-packages (from pystan>=2.14->fbprophet)
@bletham
Copy link
Contributor

bletham commented Jan 6, 2018

That's odd. Did pystan actually install?

import pystan
pystan.__version__

If not could you try

pip install --upgrade pystan

and see if it works? and then same for fbprophet?

@maartenmennes
Copy link

I encountered the same issue upon install

@bletham
Copy link
Contributor

bletham commented Feb 1, 2018

@maartenmennes Can you check the pystan info from my previous post? and is there Anaconda or something like that involved?

@maartenmennes
Copy link

everything seemed to have installed fine, despite the error message regarding pystan.

It was a clean environment created on centos7.2 with: conda create --name py36 python=3.6 anaconda

@bletham
Copy link
Contributor

bletham commented Feb 2, 2018

Including fbprophet is working?

@maartenmennes
Copy link

maartenmennes commented Feb 5, 2018

Yep, from fbprophet import Prophet is working as advertised... It then only took me a while to realize that your X and Y variables HAVE to be called 'ds' and 'y'...

@bletham
Copy link
Contributor

bletham commented Feb 5, 2018

Interesting, I'm not sure what is going on with that error, I haven't seen this myself with pip installs.

As for ds and y, yes that definitely should give better error messages, #433.

@rogeriomgatto
Copy link

It seems this error only occurs when package wheel is already installed. If wheel is not installed, setup.py bdist_wheel will not be invoked. If wheel is installed, wheel building fails because it happens before pystan has been installed. Perhaps pystan should be listed in both install_requires and setup_requires?

@robertmuil
Copy link

I have seen this issue too: +1 for including pystan explicitly in package requirements.

@k6ef
Copy link

k6ef commented Apr 5, 2018

Just recently came across this and found that removing pystan and re-installing it, I was able to build/install fbprophet.

@robertmuil
Copy link

@k6ef Yes, simply retrying the installation will usually work because PyStan is installed after fbprophet fails the first time. Be nice if it worked first time though.
BTW, installing with conda instead of pip works first time.

@bletham bletham added the bug label Apr 10, 2018
@bletham bletham added this to the v0.3-release milestone May 25, 2018
@bletham
Copy link
Contributor

bletham commented May 28, 2018

So, adding pystan to setup_requires does indeed make sure that it is in place before trying to build fbprophet, and thus avoids this confusing error message.

However, it seems (TIL) that pip does not directly interact with setup_requires. Rather, during the build it uses easy_install to install everything from setup_requires. easy_install does not support wheels, and so it means that pystan has to be built from source. This takes forever and uses a ton of RAM. It is thus not a good option here.

I think the best fix we can get for this is just to update the install instructions to say to install pystan with pip before installing fbprophet with pip.

@rogeriomgatto
Copy link

This is on the release notes for pip 10:

Support for packages specifying build dependencies in pyproject.toml (see PEP 518). Packages which specify one or more build dependencies this way will be built into wheels in an isolated environment with those dependencies installed. (#3691)

I did a quick check and adding python/pyproject.toml (and a corresponding entry in MANIFEST.in) seems to solve the issue with pip >= 10, although I would prefer that more people tested this before committing.

Should I send a merge request? It's a very simple change:

diff --git a/python/MANIFEST.in b/python/MANIFEST.in
index 10c5fe3..a80a5ec 100644
--- a/python/MANIFEST.in
+++ b/python/MANIFEST.in
@@ -6,4 +6,7 @@ include LICENSE
 prune fbprophet/stan_models
 
 # Necessary for tests to run
-include fbprophet/tests/*.csv
\ No newline at end of file
+include fbprophet/tests/*.csv
+
+# build dependencies
+include pyproject.toml
$ cat python/pyproject.toml 
[build-system]
# Minimum requirements for the build system to execute.
requires = ["setuptools", "wheel", "pystan>=2.14"]

@Teoretic6
Copy link

Struggled with this issue too today while installing fbprophet on Ubuntu 16.04.

Only thing that helped me to solve this issue: upgrade pip to version 10 and later

After that pip install fbprophet started to work as intended.

@bletham bletham removed this from the v0.3-release milestone Jun 7, 2018
@bletham
Copy link
Contributor

bletham commented Sep 25, 2018

Here are some commands to repro this issue:

cd /path/to/prophet/python
sudo pip3 uninstall --yes fbprophet
sudo pip3 uninstall --yes pystan
sudo rm -rf dist
sudo python3 setup.py sdist

cd ~/tmp/
sudo rm -rf test_cache
sudo mkdir test_cache
sudo pip3 install fbprophet --find-links file:///path/to/prophet/python/dist/ --cache-dir test_cache

@rogeriomgatto that seems to do the trick, do you want to make a PR? I'll merge it ASAP if you do.

That will only fix the issue for pip >= 10, but that is a reasonable requirement. The issue can also be fixed by pip3 install fbprophet --no-cache-dir, which prevents building the wheel locally.

@bletham
Copy link
Contributor

bletham commented Sep 25, 2018

#685 just got merged which fixes this for pip >=10 by using a pyproject.toml file.

@bletham
Copy link
Contributor

bletham commented Dec 20, 2018

This has been pushed to PyPI and should be fixed now for pip >=10.

@bletham
Copy link
Contributor

bletham commented Jan 8, 2019

We reverted the addition of the pyproject.toml file in 34af9ef. Here's the deal:

fbprophet requires pystan to build. pip install will by default do the install in this order: (1) build a wheel for fbprophet, (2) install package dependencies, (3) install fbprophet from the wheel.

If pystan is not already installed, this is a problem: Pystan is needed to build the wheel in (1), but is not installed until (2). Thus building the wheel fails with the error at the start of this issue.

The issue is not super serious, because when the wheel fails to build, step (3) is replaced with installing the package from source, which then succeeds because it happens after pystan is installed in (2). But having an error message during install is obviously not ideal and can be confusing to users. Note also that if pystan is already installed, the wheel will successfully build.

Hence we tried to solve the problem in the recommended way, which is to specify build dependencies in a pyproject.toml file. This changes the pip install flow first step to be (1) Set up a build environment, install all of the packages from pyproject.toml in that environment, and build the wheel in that environment. The install then proceeds to steps 2 and 3 as above, outside of the build environment.

This solves the problem because pytsan is installed in the build environment prior to building the wheel.

However, it introduces another significant issue: The build environment is no longer the same as the run environment. Pystan is installed from scratch in the build environment, and is not necessarily the same version or configured in the same way as in the run environment, which is really problematic because Pystan can require some special configuration to get it to build correctly. We ran into a specific issue with this in OSX where building the wheel would fail in the build environment, but work fine outside the build environment. The issue is that Pystan is not hooked up correctly to the C++ compiler in the build environment - we haven't figured out why yet, but if we ran into this issue on one of our machines certainly other users will too.

Another issue is that the build environment does not necessarily have the same version of Pystan as the system. For instance, I have Pystan 2.18.0 installed in my system python, but the build environment pulled the latest version of Pystan (2.18.1) and built the wheel using that. This can be a serious issue for users that already have pystan installed and are upgrading fbprophet, because changes in Stan can make it so that models compiled under one version of Pystan cannot be loaded in another. For instance, if I have Pystan 2.14 installed, the models will be compiled under Pystan 2.18.1, but my local 2.14 will not be upgraded. When I try to load the models in my 2.14, it will fail.

We need to be sure that the Pystan used in the build environment is the same version and hooked up the same way as in the system py, and so have removed pyproject.toml until we figure out how that can be done.

In the meantime: If you get this error, you can ignore it. If you don't want to avoid it, just install pystan before installing fbprophet.

@bletham bletham reopened this Jan 8, 2019
@johnnyheineken
Copy link

johnnyheineken commented Apr 7, 2021

I had this issue with Python 3.9, miniconda debian docker image

If you are currently having issues with importing pystan in fbprophet, this is most likely caused by pystan 3.0.
See here:

Use import stan instead of import pystan.

I recommend to downgrade pystan to 2.19.1.1 - latest pre-3 version.
I recommend to downgrade to python 3.8 (repositories contain pre-compiled binaries, but not for 3.9)

Installation worked for me to install pystan using conda, and fbprophet using pip

If you would like to use 3.9 - check that g++, gcc is installed.

@djsegal
Copy link

djsegal commented Jun 7, 2021

I can't seem to find any v2.x.x.x versions for pystan?

@z4yed
Copy link

z4yed commented Jun 21, 2021

According to the installation page of FbProphet:

Install pystan with pip before using pip to install prophet

pystan>=3.0 is currently not supported

$ pip install pystan==2.19.1.1
$
$ pip install prophet

@matouka-suzuki
Copy link

As @z4yed said, this works for me.

$ python3 -m pip install "pystan==2.19.1.1"

You saved my day! Thank you.

johnandersen777 pushed a commit to johnandersen777/dffml that referenced this issue Oct 1, 2021
… (comment)

Signed-off-by: John Andersen <johnandersenpdx@gmail.com>
johnandersen777 pushed a commit to intel/dffml that referenced this issue Oct 1, 2021
… (comment)

Signed-off-by: John Andersen <johnandersenpdx@gmail.com>
@amirhosein-kia-darbandsary

just change version of pystan and install this power full library
i think suitable version of pystan is ---> 2.19.1.1
just run this command = (pip install pystan==2.19.1.1)
have a nice day all

@vishalgarg837
Copy link

I had this issue with Python 3.9, miniconda debian docker image

If you are currently having issues with importing pystan in fbprophet, this is most likely caused by pystan 3.0. See here:

Use import stan instead of import pystan.

I recommend to downgrade pystan to 2.19.1.1 - latest pre-3 version. I recommend to downgrade to python 3.8 (repositories contain pre-compiled binaries, but not for 3.9)

Installation worked for me to install pystan using conda, and fbprophet using pip

If you would like to use 3.9 - check that g++, gcc is installed.

@johnnyheineken Could you make pystan(2.19.1.1) work with Python 3.9? I am still getting the same error:

Running setup.py install for pystan: finished with status 'error'
#12 205.6     ERROR: Command errored out with exit status 1:
#12 205.6      command: /opt/venv/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-vi06qubg/pystan_302631e0389741a98e043f90e50901b8/setup.py'"'"'; __file__='"'"'/tmp/pip-install-vi06qubg/pystan_302631e0389741a98e043f90e50901b8/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-bj8_2tth/install-record.txt --single-version-externally-managed --compile --install-headers /opt/venv/include/site/python3.9/pystan
#12 205.6          cwd: /tmp/pip-install-vi06qubg/pystan_302631e0389741a98e043f90e50901b8/
#12 205.6     Complete output (17893 lines):
#12 205.6     Compiling pystan/_api.pyx because it depends on /opt/venv/lib/python3.9/site-packages/Cython/Includes/libcpp/vector.pxd.
#12 205.6     Compiling pystan/_chains.pyx because it depends on /opt/venv/lib/python3.9/site-packages/Cython/Includes/libcpp/vector.pxd.
#12 205.6     [1/2] Cythonizing pystan/_api.pyx
#12 205.6     [2/2] Cythonizing pystan/_chains.pyx

johnandersen777 pushed a commit to johnandersen777/dffml that referenced this issue Mar 11, 2022
… (comment)

Signed-off-by: John Andersen <johnandersenpdx@gmail.com>
johnandersen777 pushed a commit to intel/dffml that referenced this issue Mar 12, 2022
… (comment)

Signed-off-by: John Andersen <johnandersenpdx@gmail.com>
@shraddhajadhav7
Copy link

We reverted the addition of the pyproject.toml file in 34af9ef. Here's the deal:

fbprophet requires pystan to build. pip install will by default do the install in this order: (1) build a wheel for fbprophet, (2) install package dependencies, (3) install fbprophet from the wheel.

If pystan is not already installed, this is a problem: Pystan is needed to build the wheel in (1), but is not installed until (2). Thus building the wheel fails with the error at the start of this issue.

The issue is not super serious, because when the wheel fails to build, step (3) is replaced with installing the package from source, which then succeeds because it happens after pystan is installed in (2). But having an error message during install is obviously not ideal and can be confusing to users. Note also that if pystan is already installed, the wheel will successfully build.

Hence we tried to solve the problem in the recommended way, which is to specify build dependencies in a pyproject.toml file. This changes the pip install flow first step to be (1) Set up a build environment, install all of the packages from pyproject.toml in that environment, and build the wheel in that environment. The install then proceeds to steps 2 and 3 as above, outside of the build environment.

This solves the problem because pytsan is installed in the build environment prior to building the wheel.

However, it introduces another significant issue: The build environment is no longer the same as the run environment. Pystan is installed from scratch in the build environment, and is not necessarily the same version or configured in the same way as in the run environment, which is really problematic because Pystan can require some special configuration to get it to build correctly. We ran into a specific issue with this in OSX where building the wheel would fail in the build environment, but work fine outside the build environment. The issue is that Pystan is not hooked up correctly to the C++ compiler in the build environment - we haven't figured out why yet, but if we ran into this issue on one of our machines certainly other users will too.

Another issue is that the build environment does not necessarily have the same version of Pystan as the system. For instance, I have Pystan 2.18.0 installed in my system python, but the build environment pulled the latest version of Pystan (2.18.1) and built the wheel using that. This can be a serious issue for users that already have pystan installed and are upgrading fbprophet, because changes in Stan can make it so that models compiled under one version of Pystan cannot be loaded in another. For instance, if I have Pystan 2.14 installed, the models will be compiled under Pystan 2.18.1, but my local 2.14 will not be upgraded. When I try to load the models in my 2.14, it will fail.

We need to be sure that the Pystan used in the build environment is the same version and hooked up the same way as in the system py, and so have removed pyproject.toml until we figure out how that can be done.

In the meantime: If you get this error, you can ignore it. If you don't want to avoid it, just install pystan before installing fbprophet.

I'm still facing this issue. Can you tell me what to do exactly so this error won't be there? So much confused right now, been stuck on this for so long.

@akosfurton
Copy link

@shraddhajadhav7 , Prophet 1.1 has been released and has simplified the install workflow and removed the Pystan requirement

You can now pip install prophet to install a pre-compiled wheel

@mintaow
Copy link

mintaow commented Jul 27, 2022

I just went through the same problem and resolved it using this issues (which was replied by a meta employee):

  1. pip install pystan==2.19.1.1 (you have to specify some old version otherwise it will install the latest version, which is titled stan rather than pystan and installing fbprophet will prompt ModuleNotFound "pystan" error.
  2. pip install fbprophet

@erajabi
Copy link

erajabi commented May 16, 2023

I just went through the same problem and resolved it using this issues (which was replied by a meta employee):

  1. pip install pystan==2.19.1.1 (you have to specify some old version otherwise it will install the latest version, which is titled stan rather than pystan and installing fbprophet will prompt ModuleNotFound "pystan" error.
  2. pip install fbprophet

As of May 15, 2023, this approach does not work.

@WardBrian
Copy link
Collaborator

Closing due to PyStan no longer being a dependency of prophet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests