-
Notifications
You must be signed in to change notification settings - Fork 144
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
tensorflow: 'module' object has no attribute 'argv' #81
Comments
I think it would be good to make it so the args can be set in PyConfig |
Can you set Python's PyConfig is for pre-init parameters that apply to the entire Python interpreter. |
Setting |
I've recently faced the same issue with shared module feature. In this case this workaround can't be applied as adding shared modules happens in Jep constructor. Could it be qualified as issue in this case? |
@akrauchanka, can you explain your use case in more detail? |
@ndjensen, sure. I've added tensorflow module to shared modules list, but with Jep constructor call I've got the same exception as mentioned in issue title. Workaround you've provided hadn't worked, because exception has been thrown on constructor call. So I've downloaded sources, made changes to C code to pass empty string to embedded interpreter as parameter during creation. Then I rebuild JEP from sources and tried it - works good. |
It sounds like for flexibility we need PyConfig to have a default argv of empty string "" so it can be set globally. That code would be CPython mostly using
Then we also need to overload Jep.runScript() to take a list of arguments and we'd manipulate sys.argv with Python code. Update: Went with Jep.setSharedModulesArgv() since it's not quite the same as PyConfig. Skipping Jep.runScript() for this ticket. |
Does anybody know why tensorflow requires sys.argv? If tensorflow would like to work well in an embedded environment, it shouldn't be so reliant on sys.argv. That said, the entire concept of shared modules was born from a lack of external libraries working well within embedded environments. Therefore, we will strive to make shared modules work as well as possible. |
For this ticket we want to add to PyConfig a variable argv, probably a String[], and then in the CPython where PyConfig is used (search for pyembed_preinit) use PySys_SetArgvEx. We'll split off Jep.runScript() changes to a separate task. Target branch dev_3.7. If anyone wants to submit a pull request it will get done faster, otherwise I will eventually get to it. |
I really hope this issue is solved. To have tensorflow 1.2 in shared module, I make a file named 'tf_init.py' under my working directory which looks below. Then I initialize Jep using Before doing any Keras/TF-related stuff, I do jep.eval("import tf_init") so that sys.argv is set in the top interpreter. For the top interpreter to see "tf_init.py" I set PYTHONPATH to my working directory. I had to do this because I don't think Jep provides a means to set an include path for the top interpreter, which is irrelevant to this issue but I hope someone to figure it out as well as this issue. |
Ok, two things:
A simple test could be something like: Jep.setSharedModulesArgv("");
Jep jep = new Jep();
jep.eval("import tensorflow"); If it works I will merge it into the main repository's dev_3.7. |
I tested your code of branch dev_3.7.
|
I don't think this is specific to tensorflow; it can be a problem for other programs which call the argparse module.
Upon executing argparse.ArgumentParser(), I got the error: The simplest way to avoid this error seems to declare another class in tensorflow/python/platform/flags.py that doesn't depend on argparse.ArgumentParser. |
@eastcirclek, thanks for testing. I've merged the code from my fork to the main jep dev_3.7. Ok, I agree we don't need a tensorflow ticket based on your investigation. I have concerns about the complexity we're adding to Jep to support quirks of various CPython extensions (the entire shared modules concept was added to work around issues with numpy). But since it helps the Jep community we'll keep doing our best. |
I'm sure of the importance of having shared module in Jep. Python libraries like Scipy, H5py, Theano, and TensorFlow to name a few are not a pure Python library, so without Jep they cannot be used inside JVM-based data processing engines in which multiple sub-interpreters should be created and destroyed as user jobs are created and finished. TensorFlow supports its Java API and I tested it. However, Tensorflow Java API somehow shows worse performance than TensorFlow Python API; so I stick to use Jep+TensorFlow Python API. So there's no doubt about shared module to me 💯 |
Caused when trying to import tensorflow (v1.2). Most likely caused by
PySys_SetArgv
not having been called?Java 8, Python 2.7, Jep 3.6.3, running from within an IntelliJ IDEA scala project.
Full error:
test.py:
The text was updated successfully, but these errors were encountered: