question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot create pex with fbprophet

See original GitHub issue

Hello,

I’m trying to create a pex with fbprophet in it, and it doesn’t seem to work. I’m on python 3.6 with the latest version of pex. I can successfully install fbprophet with pip, and run my code using fbprophet.

When trying to build a simple pex with it, it fails:

pex pystan fbprophet -o fbprophet.pex gives me:

ERROR: Command errored out with exit status 1:
   command: /home/t.henri/.pex/venvs/s/2dea2668/venv/bin/python3.6 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-npc93b27/setup.py'"'"'; __file__='"'"'/tmp/pip-req-build-npc93b27/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 /tmp/pip-wheel-mkxvmgl5
       cwd: /tmp/pip-req-build-npc93b27/
  Complete output (40 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib
  creating build/lib/fbprophet
  creating build/lib/fbprophet/stan_model
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/tmp/pip-req-build-npc93b27/setup.py", line 149, in <module>
      long_description_content_type='text/markdown',
    File "/home/t.henri/.pex/venvs/s/2dea2668/venv/lib64/python3.6/site-packages/setuptools/__init__.py", line 169, in setup
      return distutils.core.setup(**attrs)
    File "/usr/lib64/python3.6/distutils/core.py", line 148, in setup
      dist.run_commands()
    File "/usr/lib64/python3.6/distutils/dist.py", line 955, in run_commands
      self.run_command(cmd)
    File "/usr/lib64/python3.6/distutils/dist.py", line 974, in run_command
      cmd_obj.run()
    File "/home/t.henri/.pex/venvs/s/2dea2668/venv/lib64/python3.6/site-packages/wheel/bdist_wheel.py", line 299, in run
      self.run_command('build')
    File "/usr/lib64/python3.6/distutils/cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "/usr/lib64/python3.6/distutils/dist.py", line 974, in run_command
      cmd_obj.run()
    File "/usr/lib64/python3.6/distutils/command/build.py", line 135, in run
      self.run_command(cmd_name)
    File "/usr/lib64/python3.6/distutils/cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "/usr/lib64/python3.6/distutils/dist.py", line 974, in run_command
      cmd_obj.run()
    File "/tmp/pip-req-build-npc93b27/setup.py", line 48, in run
      build_models(target_dir)
    File "/tmp/pip-req-build-npc93b27/setup.py", line 36, in build_models
      from fbprophet.models import StanBackendEnum
    File "/tmp/pip-req-build-npc93b27/fbprophet/__init__.py", line 8, in <module>
      from fbprophet.forecaster import Prophet
    File "/tmp/pip-req-build-npc93b27/fbprophet/forecaster.py", line 14, in <module>
      import numpy as np
  ModuleNotFoundError: No module named 'numpy'
  ----------------------------------------
  ERROR: Failed building wheel for fbprophet
ERROR: Failed to build one or more wheels

It seems to be a known issue when checking on the internet, where people had trouble installing it with pip, and most of the fix suggest to use conda. Do you have any idea how I could fix it ?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jsiroiscommented, May 5, 2022

Trimming things down, the minimal repro:

$ pex fbprophet -o fbprophet.pex
  ERROR: Command errored out with exit status 1:
   command: /home/jsirois/.pex/venvs/s/a05bd7da/venv/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-2pkux84n/setup.py'"'"'; __file__='"'"'/tmp/pip-req-build-2pkux84n/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 /tmp/pip-wheel-vu7ac55f
       cwd: /tmp/pip-req-build-2pkux84n/
  Complete output (40 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib
  creating build/lib/fbprophet
  creating build/lib/fbprophet/stan_model
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/tmp/pip-req-build-2pkux84n/setup.py", line 122, in <module>
      setup(
    File "/home/jsirois/.pex/venvs/s/a05bd7da/venv/lib/python3.10/site-packages/setuptools/__init__.py", line 169, in setup
      return distutils.core.setup(**attrs)
    File "/home/jsirois/.pyenv/versions/3.10.2/lib/python3.10/distutils/core.py", line 148, in setup
      dist.run_commands()
    File "/home/jsirois/.pyenv/versions/3.10.2/lib/python3.10/distutils/dist.py", line 966, in run_commands
      self.run_command(cmd)
    File "/home/jsirois/.pyenv/versions/3.10.2/lib/python3.10/distutils/dist.py", line 985, in run_command
      cmd_obj.run()
    File "/home/jsirois/.pex/venvs/s/a05bd7da/venv/lib/python3.10/site-packages/wheel/bdist_wheel.py", line 299, in run
      self.run_command('build')
    File "/home/jsirois/.pyenv/versions/3.10.2/lib/python3.10/distutils/cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "/home/jsirois/.pyenv/versions/3.10.2/lib/python3.10/distutils/dist.py", line 985, in run_command
      cmd_obj.run()
    File "/home/jsirois/.pyenv/versions/3.10.2/lib/python3.10/distutils/command/build.py", line 135, in run
      self.run_command(cmd_name)
    File "/home/jsirois/.pyenv/versions/3.10.2/lib/python3.10/distutils/cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "/home/jsirois/.pyenv/versions/3.10.2/lib/python3.10/distutils/dist.py", line 985, in run_command
      cmd_obj.run()
    File "/tmp/pip-req-build-2pkux84n/setup.py", line 48, in run
      build_models(target_dir)
    File "/tmp/pip-req-build-2pkux84n/setup.py", line 36, in build_models
      from fbprophet.models import StanBackendEnum
    File "/tmp/pip-req-build-2pkux84n/fbprophet/__init__.py", line 8, in <module>
      from fbprophet.forecaster import Prophet
    File "/tmp/pip-req-build-2pkux84n/fbprophet/forecaster.py", line 14, in <module>
      import numpy as np
  ModuleNotFoundError: No module named 'numpy'
  ----------------------------------------
  ERROR: Failed building wheel for fbprophet
ERROR: Failed to build one or more wheels
...

N.B. that fbprophet is sdist-only and the above backtrace is from running the setup.py in the sdist to build a wheel from it (bdist_wheel is the subcommand):

/home/jsirois/.pex/venvs/s/a05bd7da/venv/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-2pkux84n/setup.py'"'"'; __file__='"'"'/tmp/pip-req-build-2pkux84n/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 /tmp/pip-wheel-vu7ac55f

Also note, that importing setup.py leads to importing numpy indirectly:

File "/tmp/pip-req-build-npc93b27/setup.py", line 36, in build_models
      from fbprophet.models import StanBackendEnum
    File "/tmp/pip-req-build-npc93b27/fbprophet/__init__.py", line 8, in <module>
      from fbprophet.forecaster import Prophet
    File "/tmp/pip-req-build-npc93b27/fbprophet/forecaster.py", line 14, in <module>
      import numpy as np

So the issue here is that to even run the build you must 1st resolve numpy. Now there is a poor mechanism for this built into setup.py via setuptools by using setup_requires (as opposed to install_requires), but fbprophet does not use this:

$ curl -sSL https://files.pythonhosted.org/packages/1a/b5/9c3fefa8a7b839729df57deedf0a69815841dfb88f0df911f34d998230b7/fbprophet-0.7.1.tar.gz -O
$ tar -xzf fbprophet-0.7.1.tar.gz 
$ grep -C3 setup_requires fbprophet-0.7.1/setup.py 
    author_email='sjtz@pm.me',
    license='MIT',
    packages=find_packages(),
    setup_requires=[
    ],
    install_requires=install_requires,
    python_requires='>=3',

It looks like the offending import in setup.py got removed though and latest on main works:

$ pex "git+https://github.com/facebook/prophet@df411c91929e82bb8d2c0f3a8b758cacdd6e1e60#egg=prophet&subdirectory=python" -o fbprophet.pex
$ ./fbprophet.pex 
Python 3.10.2 (main, Feb 12 2022, 09:55:19) [GCC 11.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import prophet
Importing plotly failed. Interactive plots will not work.
>>> dir(prophet)
['Prophet', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', 'diagnostics', 'forecaster', 'hdays', 'make_holidays', 'models', 'plot']
>>> 
now exiting InteractiveConsole...

You may be able to use an older sha - I did not dig to see at which commit the issue is fixed.

So you can use a VCS requirement like I did above for fbprohet (which you can see they re-named to prophet) or else you’ll need to wait to their next release to pick up that fix in an official distribution they publish to PyPI.

1reaction
jsiroiscommented, May 5, 2022

That won’t be it, this is a build-time dependency not runtime. I’ll respond more fully in a bit on what you might be able to do.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot use 'pip install fbprophet' to install prophet on mac #17
Failed building wheel for fbprophet. Running setup.py clean for fbprophet. Failed to build fbprophet. Installing collected packages: ...
Read more >
Building .pex files — pex 2.1.51 documentation - Read the Docs
This command creates a pex file containing pex and requests, using the console script named “pex”, saving it in ~/bin/pex. At this point,...
Read more >
Cannot install Tensorflow in R, "could not find a Python ...
No, py_config() still shows me my default python path, not the one to my conda installation. I'm seriously considering either dual-booting ...
Read more >
Installing FBProphet/Prophet for Time Series Forecasting in ...
The main problem of the installation, in my case because I already installed python 3.9 so, the prophet can't be installed. I don't...
Read more >
Packaging a Machine Learning Project using Python PEX
Use pex python library to package a python project for deployment.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found