stan-dev / pystan2

PyStan, the Python interface to Stan
GNU General Public License v3.0
920 stars 189 forks source link

Trouble importing Pystan #155

Closed dberma15 closed 9 years ago

dberma15 commented 9 years ago

I am having trouble importing pystan. I am using a 64bit windows 7 system. I successfully installed it using Anaconda and pycharm. However, when I go to a python console and type: import pystan I get the following response:

Traceback (most recent call last): File "C:\Users\daniel\Anaconda\lib\site-packages\IPython\core\interactiveshell.py", line 3032, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "", line 1, in import pystan File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 4.0.4\helpers\pydev\pydev_import_hook.py", line 21, in do_import module = self._system_import(name, _args, _kwargs) File "C:\Users\daniel\Anaconda\lib\site-packages\pystaninit.py", line 9, in from pystan.api import stanc, stan File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 4.0.4\helpers\pydev\pydev_import_hook.py", line 21, in do_import module = self._system_import(name, _args, _kwargs) File "C:\Users\daniel\Anaconda\lib\site-packages\pystan\api.py", line 13, in import pystan._api # stanc wrapper File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 4.0.4\helpers\pydev\pydev_import_hook.py", line 21, in do_import module = self._system_import(name, _args, *_kwargs) File "C:\Users\daniel\Anaconda\lib\site-packages\pyximport\pyximport.py", line 431, in load_module language_level=self.language_level) File "C:\Users\daniel\Anaconda\lib\site-packages\pyximport\pyximport.py", line 209, in load_module inplace=build_inplace, language_level=language_level) File "C:\Users\daniel\Anaconda\lib\site-packages\pyximport\pyximport.py", line 186, in build_module reload_support=pyxargs.reload_support) File "C:\Users\daniel\Anaconda\lib\site-packages\pyximport\pyxbuild.py", line 100, in pyx_to_dll dist.run_commands() File "C:\Users\daniel\Anaconda\lib\distutils\dist.py", line 953, in run_commands self.run_command(cmd) File "C:\Users\daniel\Anaconda\lib\distutils\dist.py", line 972, in run_command cmd_obj.run() File "C:\Users\daniel\Anaconda\lib\site-packages\Cython\Distutils\build_ext.py", line 163, in run _build_ext.build_ext.run(self) File "C:\Users\daniel\Anaconda\lib\distutils\command\build_ext.py", line 337, in run self.build_extensions() File "C:\Users\daniel\Anaconda\lib\site-packages\Cython\Distutils\build_ext.py", line 171, in build_extensions self.build_extension(ext) File "C:\Users\daniel\Anaconda\lib\distutils\command\build_ext.py", line 496, in build_extension depends=ext.depends) File "C:\Users\daniel\Anaconda\lib\distutils\msvc9compiler.py", line 473, in compile self.initialize() File "C:\Users\daniel\Anaconda\lib\distutils\msvc9compiler.py", line 383, in initialize vc_env = query_vcvarsall(VERSION, plat_spec) File "C:\Users\daniel\Anaconda\lib\distutils\msvc9compiler.py", line 271, in query_vcvarsall raise DistutilsPlatformError("Unable to find vcvarsall.bat") ImportError: Building module pystan._api failed: ['DistutilsPlatformError: Unable to find vcvarsall.bat\n']

I'm not really sure what's going on.

ariddell commented 9 years ago

Installing PyStan on Windows is challenging and something of a work-in-progress. If you have experience with compiling C++ programs on windows, we'd love some help.

Here are the current instructions: https://pystan.readthedocs.org/en/latest/windows.html#windows

If you're using Python 2.7 and Anaconda, you shouldn't have any problems.

dberma15 commented 9 years ago

I'm now getting this error:

In[25]: import pystan Traceback (most recent call last): File "C:\Users\daniel\Anaconda\lib\site-packages\IPython\core\interactiveshell.py", line 3032, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "", line 1, in import pystan File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 4.0.4\helpers\pydev\pydev_import_hook.py", line 21, in do_import module = self._system_import(name, _args, _kwargs) File "C:\Users\daniel\Anaconda\lib\site-packages\pystaninit.py", line 9, in from pystan.api import stanc, stan File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 4.0.4\helpers\pydev\pydev_import_hook.py", line 21, in do_import module = self._system_import(name, _args, _kwargs) File "C:\Users\daniel\Anaconda\lib\site-packages\pystan\api.py", line 13, in import pystan._api # stanc wrapper File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 4.0.4\helpers\pydev\pydev_import_hook.py", line 21, in do_import module = self._system_import(name, _args, *_kwargs) File "C:\Users\daniel\Anaconda\lib\site-packages\pyximport\pyximport.py", line 431, in load_module language_level=self.language_level) File "C:\Users\daniel\Anaconda\lib\site-packages\pyximport\pyximport.py", line 209, in load_module inplace=build_inplace, language_level=language_level) File "C:\Users\daniel\Anaconda\lib\site-packages\pyximport\pyximport.py", line 186, in build_module reload_support=pyxargs.reload_support) File "C:\Users\daniel\Anaconda\lib\site-packages\pyximport\pyxbuild.py", line 100, in pyx_to_dll dist.run_commands() File "C:\Users\daniel\Anaconda\lib\distutils\dist.py", line 953, in run_commands self.run_command(cmd) File "C:\Users\daniel\Anaconda\lib\distutils\dist.py", line 972, in run_command cmd_obj.run() File "C:\Users\daniel\Anaconda\lib\site-packages\Cython\Distutils\build_ext.py", line 163, in run _build_ext.build_ext.run(self) File "C:\Users\daniel\Anaconda\lib\distutils\command\build_ext.py", line 337, in run self.build_extensions() File "C:\Users\daniel\Anaconda\lib\site-packages\Cython\Distutils\build_ext.py", line 171, in build_extensions self.build_extension(ext) File "C:\Users\daniel\Anaconda\lib\distutils\command\build_ext.py", line 496, in build_extension depends=ext.depends) File "C:\Users\daniel\Anaconda\lib\distutils\ccompiler.py", line 574, in compile self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts) File "C:\Users\daniel\Anaconda\lib\distutils\cygwinccompiler.py", line 166, in _compile raise CompileError, msg ImportError: Building module pystan._api failed: ["CompileError: command 'gcc' failed: No such file or directory\n"]

ariddell commented 9 years ago

Great.

I'm surprised this is necessary---that is, I would think Anaconda would have taken care of it. Do you have any suggestions for alterations to the installation instructions on Windows?

On 06/17, dberma15 wrote:

I was able to fix the problem by going to \Anaconda\Lib\distutils and creating a file called distutils.cfg with the contents:

[build] compiler = mingw32

[build_ext] compiler = mingw32

Now I can import without errors.


Reply to this email directly or view it on GitHub: https://github.com/stan-dev/pystan/issues/155#issuecomment-112968051

dberma15 commented 9 years ago

I apologize, but I was wrong about it working. It took a while for the error message to appear but this is what I got:

In[25]: import pystan Traceback (most recent call last): File "C:\Users\daniel\Anaconda\lib\site-packages\IPython\core\interactiveshell.py", line 3032, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "", line 1, in import pystan File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 4.0.4\helpers\pydev\pydev_import_hook.py", line 21, in do_import module = self.system_import(name, args, kwargs) File "C:\Users\daniel\Anaconda\lib\site-packages\pystan_init.py", line 9, in from pystan.api import stanc, stan File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 4.0.4\helpers\pydev\pydev_import_hook.py", line 21, in do_import module = self._system_import(name, args, kwargs) File "C:\Users\daniel\Anaconda\lib\site-packages\pystan\api.py", line 13, in import pystan._api # stanc wrapper File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 4.0.4\helpers\pydev\pydev_import_hook.py", line 21, in do_import module = self._system_import(name, args, *kwargs) File "C:\Users\daniel\Anaconda\lib\site-packages\pyximport\pyximport.py", line 431, in load_module language_level=self.language_level) File "C:\Users\daniel\Anaconda\lib\site-packages\pyximport\pyximport.py", line 209, in load_module inplace=build_inplace, language_level=language_level) File "C:\Users\daniel\Anaconda\lib\site-packages\pyximport\pyximport.py", line 186, in build_module reload_support=pyxargs.reload_support) File "C:\Users\daniel\Anaconda\lib\site-packages\pyximport\pyxbuild.py", line 100, in pyx_to_dll dist.run_commands() File "C:\Users\daniel\Anaconda\lib\distutils\dist.py", line 953, in run_commands self.run_command(cmd) File "C:\Users\daniel\Anaconda\lib\distutils\dist.py", line 972, in run_command cmd_obj.run() File "C:\Users\daniel\Anaconda\lib\site-packages\Cython\Distutils\build_ext.py", line 163, in run _build_ext.build_ext.run(self) File "C:\Users\daniel\Anaconda\lib\distutils\command\build_ext.py", line 337, in run self.build_extensions() File "C:\Users\daniel\Anaconda\lib\site-packages\Cython\Distutils\build_ext.py", line 171, in build_extensions self.build_extension(ext) File "C:\Users\daniel\Anaconda\lib\distutils\command\build_ext.py", line 496, in build_extension depends=ext.depends) File "C:\Users\daniel\Anaconda\lib\distutils\ccompiler.py", line 574, in compile self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts) File "C:\Users\daniel\Anaconda\lib\distutils\cygwinccompiler.py", line 166, in _compile raise CompileError, msg ImportError: Building module pystan._api failed: ["CompileError: command 'gcc' failed: No such file or directory\n"]

ariddell commented 9 years ago

It looks like it's not finding a C/C++ compiler (it's looking for gcc).

What about trying to run import pystan from the Anaconda Python REPL directly? (It looks like you might be running things from PyCharm?)

(I take it you followed the steps in the docs?)

dberma15 commented 9 years ago

That's odd. I definitely have gcc and a C/C++ compiler. I have a recent version of Visual Stuidos on my computer and I had to have a working gcc for another python package so I should be go.

What is the Anaconda Python REPL?

I have followed the steps detailed here: https://pystan.readthedocs.org/en/latest/windows.html#windows

ariddell commented 9 years ago

I agree that it's odd!

(The REPL is just what you get when you run python from a terminal (rather than via an IDE).

If you wouldn't mind running Python from a terminal window and doing an "import pystan" from there we can at least confirm that it's installed correctly.

On 06/18, dberma15 wrote:

That's odd. I definitely have gcc and a C/C++ compiler. I have a recent version of Visual Stuidos on my computer and I had to have a working gcc for another python package so I should be go.

What is the Anaconda Python REPL?

I have followed the steps detailed here: https://pystan.readthedocs.org/en/latest/windows.html#windows


Reply to this email directly or view it on GitHub: https://github.com/stan-dev/pystan/issues/155#issuecomment-113201407

dberma15 commented 9 years ago

I cannot do it at the moment but I will do it when I can, and I'll get back to you.

dberma15 commented 9 years ago

So I just went to the command line and imported pystan. I had no errors. Then I did it from the pycharm python console and it worked without errors.

ariddell commented 9 years ago

Good sign that it imported without errors.

The error message you posted did suggest there might be some miscommunication between PyCharm and Anaconda. PyStan is, like a lot of scientific software using Cython, a little picky about its environment.

Windows support for CmdStan and RStan is better than for PyStan currently.

Sorry I can't be more help.

On 06/18, dberma15 wrote:

So I just went to the command line and imported pystan. I had no errors. Then I did it from the pycharm python console and it worked without errors.


Reply to this email directly or view it on GitHub: https://github.com/stan-dev/pystan/issues/155#issuecomment-113289107

dberma15 commented 9 years ago

I'm getting another error.


ImportError Traceback (most recent call last)

in () ----> 1 import pystan C:\Users\daniel\Anaconda\lib\site-packages\pystan__init__.py in () 7 import logging 8 ----> 9 from pystan.api import stanc, stan 10 from pystan.misc import read_rdump, stan_rdump 11 from pystan.model import StanModel C:\Users\daniel\Anaconda\lib\site-packages\pystan\api.py in () 14 from pystan._compat import string_types 15 from pystan.constants import MAX_UINT ---> 16 from pystan.model import StanModel 17 18 logger = logging.getLogger('pystan') C:\Users\daniel\Anaconda\lib\site-packages\pystan\model.py in () 30 31 import Cython ---> 32 from Cython.Build.Inline import _get_build_extension 33 from Cython.Build.Dependencies import cythonize 34 C:\Users\daniel\Anaconda\lib\site-packages\Cython\Build__init__.py in () ----> 1 from .Dependencies import cythonize C:\Users\daniel\Anaconda\lib\site-packages\Cython\Build\Dependencies.py in () 47 from .. import Utils 48 from ..Utils import cached_function, cached_method, path_exists, find_root_package_dir ---> 49 from ..Compiler.Main import Context, CompilationOptions, default_options 50 51 join_path = cached_function(os.path.join) C:\Users\daniel\Anaconda\lib\site-packages\Cython\Compiler\Main.py in () 20 # main() in this file. 21 # import Parsing ---> 22 from .Scanning import PyrexScanner, FileSourceDescriptor 23 from .Errors import PyrexError, CompileError, error, warning 24 from .Symtab import ModuleScope ImportError: DLL load failed: Invalid access to memory location.
ariddell commented 9 years ago

Thanks for following up.

Is this happening in Anaconda or PyCharm?

On 06/28, dberma15 wrote:

I'm getting another error.


ImportError Traceback (most recent call last)

in () ----> 1 import pystan C:\Users\daniel\Anaconda\lib\site-packages\pystan__init__.py in () 7 import logging 8 ----> 9 from pystan.api import stanc, stan 10 from pystan.misc import read_rdump, stan_rdump 11 from pystan.model import StanModel C:\Users\daniel\Anaconda\lib\site-packages\pystan\api.py in () 14 from pystan._compat import string_types 15 from pystan.constants import MAX_UINT ---> 16 from pystan.model import StanModel 17 18 logger = logging.getLogger('pystan') C:\Users\daniel\Anaconda\lib\site-packages\pystan\model.py in () 30 31 import Cython ---> 32 from Cython.Build.Inline import _get_build_extension 33 from Cython.Build.Dependencies import cythonize 34 C:\Users\daniel\Anaconda\lib\site-packages\Cython\Build__init__.py in () ----> 1 from .Dependencies import cythonize C:\Users\daniel\Anaconda\lib\site-packages\Cython\Build\Dependencies.py in () 47 from .. import Utils 48 from ..Utils import cached_function, cached_method, path_exists, find_root_package_dir ---> 49 from ..Compiler.Main import Context, CompilationOptions, default_options 50 51 join_path = cached_function(os.path.join) C:\Users\daniel\Anaconda\lib\site-packages\Cython\Compiler\Main.py in () 20 # main() in this file. 21 # import Parsing ---> 22 from .Scanning import PyrexScanner, FileSourceDescriptor 23 from .Errors import PyrexError, CompileError, error, warning 24 from .Symtab import ModuleScope ImportError: DLL load failed: Invalid access to memory location. --- Reply to this email directly or view it on GitHub: https://github.com/stan-dev/pystan/issues/155#issuecomment-116208657
dberma15 commented 9 years ago

Unfortunately the answer is yes.

dberma15 commented 9 years ago

Actually, from pycharm it lets me import it. However, when I run pystan.stan, I gett the error

INFO:pystan:COMPILING THE C++ CODE FOR MODEL anon_model_95013624776d537c3cd7cd4d641c30e0 NOW. Traceback (most recent call last): File "C:\Users\daniel\Anaconda\lib\site-packages\IPython\core\interactiveshell.py", line 3032, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "", line 2, in iter=1000, chains=4) File "C:\Users\daniel\Anaconda\lib\site-packages\pystan\api.py", line 372, in stan save_dso=save_dso, verbose=verbose) File "C:\Users\daniel\Anaconda\lib\site-packages\pystan\model.py", line 308, in init build_extension.run() File "C:\Users\daniel\Anaconda\lib\distutils\command\build_ext.py", line 337, in run self.build_extensions() File "C:\Users\daniel\Anaconda\lib\distutils\command\build_ext.py", line 446, in build_extensions self.build_extension(ext) File "C:\Users\daniel\Anaconda\lib\distutils\command\build_ext.py", line 496, in build_extension depends=ext.depends) File "C:\Users\daniel\Anaconda\lib\distutils\ccompiler.py", line 574, in compile self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts) File "C:\Users\daniel\Anaconda\lib\distutils\cygwinccompiler.py", line 166, in _compile raise CompileError, msg CompileError: command 'gcc' failed: No such file or directory

ariddell commented 9 years ago

I'm not an expert on Windows but it would be great to support it better in the future. I have a Windows machine lying around and I have been meaning to try installing Anaconda and PyStan. I'll keep you posted.

On 06/28, dberma15 wrote:

Actually, from pycharm it lets me import it. However, when I run pystan.stan, I gett the error

INFO:pystan:COMPILING THE C++ CODE FOR MODEL anon_model_95013624776d537c3cd7cd4d641c30e0 NOW. Traceback (most recent call last): File "C:\Users\daniel\Anaconda\lib\site-packages\IPython\core\interactiveshell.py", line 3032, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "", line 2, in iter=1000, chains=4) File "C:\Users\daniel\Anaconda\lib\site-packages\pystan\api.py", line 372, in stan save_dso=save_dso, verbose=verbose) File "C:\Users\daniel\Anaconda\lib\site-packages\pystan\model.py", line 308, in init build_extension.run() File "C:\Users\daniel\Anaconda\lib\distutils\command\build_ext.py", line 337, in run self.build_extensions() File "C:\Users\daniel\Anaconda\lib\distutils\command\build_ext.py", line 446, in build_extensions self.build_extension(ext) File "C:\Users\daniel\Anaconda\lib\distutils\command\build_ext.py", line 496, in build_extension depends=ext.depends) File "C:\Users\daniel\Anaconda\lib\distutils\ccompiler.py", line 574, in compile self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts) File "C:\Users\daniel\Anaconda\lib\distutils\cygwinccompiler.py", line 166, in _compile raise CompileError, msg CompileError: command 'gcc' failed: No such file or directory


Reply to this email directly or view it on GitHub: https://github.com/stan-dev/pystan/issues/155#issuecomment-116281144

dberma15 commented 9 years ago

Thanks.

ariddell commented 9 years ago

Closing for now. The Windows instructions have changed a bit.