I woult like to check whether a (my) module, imported from PyPI is running in an AnacondaCode environment.
For PythonInExcel that was relatively easy as I can check whether file is in globals().
But under AnacondaCode file is indeed in globals().
I also tried sys.version, but that doesn’t seem very promising either.
Any ideas?
Even just testing for running under PyScript might help …
Hi and welcome!
You could try something like this, while replacing seaborn with your module name.
This returns True.
import seaborn as sns
"sns" in dir()
Thanks for the reply.
This not the solution to my problem, though.
If I run this code on an ordinary installation and seaborn is installed there, I get True as well.
And I want to distinguish between running code normally and under AnacondaCode (or PyScript).
I have a solution myself by just testing for
"pyscript" in sys.modules
If True
, I’m running under PyScript and thus most likely AnacondaCode. If False
, it’s an ordinary installation.
OK, that sounds like you have a good solution.
The PyScript environment for Anaconda Code exists within the sandboxed web page in the Excel Add-In. At present, Anaconda Code can only run Python code within that environment, so there is no way to run another environment.
Since you have a solution, we probably don’t need to add lots of back and forth here, but I am interested in your situation and would like to understand better if possible. If you’d like to chat more 1:1 please feel free to DM me on LinkedIn.
import sys
sys.platform
If running in PyScript, this will return “emscripten”.
Thanks. That’s maybe a more reliable way.