Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 14155

How do I set environment variables in Code Cells in Scientific Mode?

$
0
0

Pycharm is not reflecting the environment variable I set in a code cell. The following code runs in Pycharm (hitting play on the entire script):

#%% <- Scientific Mode: onimport osfrom pathlib import PathCACHE_DIR = Path("/home/me/numba_cache")CACHE_DIR.touch(exist_ok=True)os.environ["NUMBA_CACHE_DIR"] = str(CACHE_DIR)from numba import jit@jit(nopython=True, cache=True)def square(x):    return x ** 2print(square(5))

However when I run the code cell, I get this error:

Traceback (most recent call last):  File "/home/me/.pycharm_helpers/pydev/pydevconsole.py", line 364, in runcode    coro = func()           ^^^^^^  File "<input>", line 11, in <module>  File "/home/me/.pyenv/versions/3.11.1/envs/my_env/lib/python3.11/site-packages/numba/core/decorators.py", line 234, in wrapper    disp.enable_caching()  File "/home/me/.pyenv/versions/3.11.1/envs/my_env/lib/python3.11/site-packages/numba/core/dispatcher.py", line 863, in enable_caching    self._cache = FunctionCache(self.py_func)                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^  File "/home/me/.pyenv/versions/3.11.1/envs/my_env/lib/python3.11/site-packages/numba/core/caching.py", line 601, in __init__    self._impl = self._impl_class(py_func)                 ^^^^^^^^^^^^^^^^^^^^^^^^^  File "/home/me/.pyenv/versions/3.11.1/envs/my_env/lib/python3.11/site-packages/numba/core/caching.py", line 337, in __init__    raise RuntimeError("cannot cache function %r: no locator available "RuntimeError: cannot cache function 'square': no locator available for file '<input>'

How do I get this to work? I've tried setting the env var in the run configuration, however that only works when the script is run, not an individual code cell


Viewing all articles
Browse latest Browse all 14155

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>