prophet icon indicating copy to clipboard operation
prophet copied to clipboard

Pip install error ModuleNotFoundError: No module named 'pystan'

Open msoedov opened this issue 7 years ago • 42 comments

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)

msoedov avatar Jan 03 '18 00:01 msoedov

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?

bletham avatar Jan 06 '18 00:01 bletham

I encountered the same issue upon install

maartenmennes avatar Jan 31 '18 13:01 maartenmennes

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

bletham avatar Feb 01 '18 23:02 bletham

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

maartenmennes avatar Feb 02 '18 09:02 maartenmennes

Including fbprophet is working?

bletham avatar Feb 02 '18 23:02 bletham

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'...

maartenmennes avatar Feb 05 '18 11:02 maartenmennes

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.

bletham avatar Feb 05 '18 19:02 bletham

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?

rogeriomgatto avatar Mar 02 '18 22:03 rogeriomgatto

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

robertmuil avatar Mar 11 '18 18:03 robertmuil

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

k6ef avatar Apr 05 '18 21:04 k6ef

@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.

robertmuil avatar Apr 06 '18 08:04 robertmuil

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.

bletham avatar May 28 '18 23:05 bletham

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"]

rogeriomgatto avatar Jun 04 '18 18:06 rogeriomgatto

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.

Teoretic6 avatar Jun 06 '18 11:06 Teoretic6

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 avatar Sep 25 '18 01:09 bletham

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

bletham avatar Sep 25 '18 20:09 bletham

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

bletham avatar Dec 20 '18 20:12 bletham

We reverted the addition of the pyproject.toml file in https://github.com/facebook/prophet/commit/34af9efb89dd22df8237a1e9363f67521e932100. 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 avatar Jan 08 '19 23:01 bletham

I am using Windows 10 and made an enviroment for Python 3.6 as failed in 3.7 After the pip install --upgrade etc, now things are working fine, but I needed to install Cython. Also needed to install pytrends and it seems to be working. Will test.

syracusepro avatar Feb 01 '19 17:02 syracusepro

This line gives error:

microsoft.changepoint_date_analysis(search = 'Microsoft profit')

Error 1 not only on this step but prior ones:

C:\Users\syrac\Desktop\stocker.py:715: FutureWarning: Comparing Series of datetimes with 'datetime.date'. Currently, the 'datetime.date' is coerced to a datetime. In the future pandas will not coerce, and a TypeError will be raised. To retain the current behavior, convert the 'datetime.date' to a datetime with 'pd.Timestamp'. train = self.stock[self.stock['Date'] > (self.max_date - pd.DateOffset(years = self.training_years)).date()] C:\Users\syrac\Anaconda3\envs\stocks\lib\site-packages\fbprophet\forecaster.py:880: FutureWarning: Series.nonzero() is deprecated and will be removed in a future version.Use Series.to_numpy().nonzero() instead min_dt = dt.iloc[dt.nonzero()[0]].min() C:\Users\syrac\Desktop\stocker.py:730: FutureWarning: Comparing Series of datetimes with 'datetime.date'. Currently, the 'datetime.date' is coerced to a datetime. In the future pandas will not coerce, and 'the values will not compare equal to the 'datetime.date'. To retain the current behavior, convert the 'datetime.date' to a datetime with 'pd.Timestamp'. change_indices.append(train[train['ds'] == changepoint.date()].index[0])

Error 2:


AttributeError Traceback (most recent call last) in ----> 1 microsoft.changepoint_date_analysis(search = 'Microsoft profit')

~\Desktop\stocker.py in changepoint_date_analysis(self, search) 786 787 print('\n Top Related Queries: \n') --> 788 print(related_queries[search]['top'].head()) 789 790 print('\n Rising Related Queries: \n')

AttributeError: 'NoneType' object has no attribute 'head'

syracusepro avatar Feb 01 '19 18:02 syracusepro

microsoft.changepoint_date_analysis(search = 'Microsoft Office')

Error:


AttributeError Traceback (most recent call last) in ----> 1 microsoft.changepoint_date_analysis(search = 'Microsoft Office')

~\Desktop\stocker.py in changepoint_date_analysis(self, search) 794 trends = trends.resample('D') 795 --> 796 trends = trends.reset_index(level=0) 797 trends = trends.rename(columns={'date': 'ds', search: 'freq'}) 798

~\Anaconda3\envs\stocks\lib\site-packages\pandas\core\resample.py in getattr(self, attr) 100 return self[attr] 101 --> 102 return object.getattribute(self, attr) 103 104 def iter(self):

AttributeError: 'DatetimeIndexResampler' object has no attribute 'reset_index'

syracusepro avatar Feb 01 '19 18:02 syracusepro

@syracusepro these errors are coming from the stocker.py file and do not seem to involve fbprophet. (fbprophet is mentioned in the first one just with a FutureWarning, which is unrelated to the errors)

bletham avatar Feb 01 '19 18:02 bletham

While I am using the Python 3.6 environment, it seems to me the class stocker has to be update in some other places such as the datetime issue to. Now, I am using Spyder IDE, then no issue, such as when using with Python Jupyter Notebook.

This is a very nice tutorial I use for educational purposes. Got it working with Spyder, and for now I hope I can keep a version that works. Thanks a lot.

syracusepro avatar Feb 01 '19 21:02 syracusepro

@bletham could we specify the same pystan version both in setup_requires option and install_requires to solve the above isolated environments problem?

justdoit0823 avatar Jun 18 '19 02:06 justdoit0823

Unfortunately there's a CLA-induced fix-abort over in #989.

javabrett avatar Jun 18 '19 02:06 javabrett

@justdoit0823 @javabrett that certainly does seem like it'd be a good solution, but setup_requires is not recommended for use with pip because packages specified in setup_requires will be installed using easy_install and not pip (https://pip.readthedocs.io/en/1.4.1/cookbook.html#controlling-setup-requires). That has the potential for a whole bunch of other issues.

bletham avatar Jun 21 '19 21:06 bletham

@bletham The above link just tells a truth that easy_install is not a good choice to manage a project's whole dependencies with the already known disadvantages. But we could also use this tool at the certain step. The packages specified in setup_requires are installed using the easy_install during the build process, rather the entire setup lifecycle.

(Note: projects listed in setup_requires will NOT be automatically installed on the system where the setup script is being run. They are simply downloaded to the ./.eggs directory if they’re not locally available already. If you want them to be installed, as well as being available when the setup script is run, you should add them to install_requires and setup_requires.)

Actually, there may be some conflict issues when package version is not matched to the other. But we can avoid these issues by specifying the same version.

Btw, it's much better if the pip could do the whole things.

justdoit0823 avatar Jun 22 '19 01:06 justdoit0823

I think pinning the version is a bit problematic too - for instance later versions of Stan require C++14. If you have an older OS, you might not be able to get c++14 support via package managers and so you would want to install an old version of Stan. Pinning the version means forcing everyone to use the oldest version of Stan that we want to support (currently 2.14).

bletham avatar Jun 25 '19 16:06 bletham

By the way, if you're trying to do this in a Docker image or a requirements.txt file, you can just list it twice, e.g.

sendgrid==5.4.1
fbprophet==0.5
fbprophet==0.5

mike-seekwell avatar Jul 22 '19 21:07 mike-seekwell

Q: maybe this is an ignorant question, but wouldn't a lot of this be mitigated by y'all publishing a wheel? Or does that force a certain version of pystan?

Not having wheel limits how this can be deployed to Azure Functions. I get that this is ofc not a main concern for Prophet and the team, but playing nice with other tools is always good.

rogeralsing avatar Aug 11 '19 09:08 rogeralsing