0

Is there a possibility to run a Jupyter Notebook in one environment and than to call a .py file (out of the JN) from another environment without pulling it over like it normally occurs?

Example: from PythonScript1 import FunctionFromScript

Edit: Because I see my problem is unclear described here some further details and the background of my question:

I want to run a matlab file from a jupyter notebook but this only works on condition which does not allow me to use tensorflow in the same JN (Using Matlab.engine and installing tensorflow at the same time).

My idea was to have the tensorflow model in one .py file which works in an anaconda env. (+ other directory) which is designed for it, while I have an JN in an other anaconda environment to call the matlab code.

Philipp
  • 3
  • 3
  • you can use `os.chdir()` if you want to use a file located at another path that is connected to your pc. but im not sure that is what you are looking for... – Eli Harold Jan 19 '22 at 21:53
  • By environment, do you mean directory? Or are you talking about running a python script using a python interpreter from a different virtual environment? – James Jan 19 '22 at 21:53
  • Is it not [Importing .py files in notebook](https://stackoverflow.com/a/62736408/10452700)? – Mario Jan 19 '22 at 22:19

3 Answers3

0

No, it is not possible because you can't have two interpreters on the same notebook. Actually, you can have two virtual environments and execute the notebook with one or other, but you can't do it with both.

If you are talking about running a module crafted with other version of python interpreter, it depends on the versions compatibility

Fran Arenas
  • 639
  • 6
  • 18
  • This doesn't seem to address the question, but maybe I am misunderstanding the question since it is unclear. – Eli Harold Jan 19 '22 at 21:57
0

I found a solution to my problem. If I build my (.py) script as a Flask, then I can run it in a different environment (+ dir.) than my Jupyter Notebook. The only difference is that I can't call the function directly, I have to access the server and import my data with "get" and "post". Thanks for the help everyone!

Philipp
  • 3
  • 3
0

You can also use SOS kernels in Jupyter Lab. SOS allows you to run multiple kernels in the same notebook and pass variables between the kernels. I was able to run Python and R kernels in a single notebook using SOS. You can use two Python kernels in your case - one with TF and one without.

P.S. I am not affiliated to SOS and am not promoting it. It worked for me and I thought I'd suggest this option.