1

How to set environment variable in pyramid

I'm trying to set environment variables in Pyramid & access it in my python script within Pyramid.

But I'm facing an error, environment variables not set.

How to set Pyramid environment variables and also do I need restart the service after setting the var.

4 replies

null
    • quantenabler
    • 11 days ago
    • Reported - view

    Also interested in this topic as well as how to have a python 3.n.m repo rather than the very early default version needed for pyramid installation.  Newer Pandas and Numpy versions are absolutely needed.

    please assist!

      • Senior Director of Product
      • Ian_Macdonald
      • 4 days ago
      • Reported - view

      Hi  

      You can add additional Python environments and add the packages you want in your selected Python environment in the admin console. By default, these use the standard Pip or Conda repositories, but you can define a custom repository if required. See Help for more details.

      Hope that helps.

      Ian

    • Senior Director of Product
    • Ian_Macdonald
    • 6 days ago
    • Reported - view

    Hi  ,

    Can you explain  a little more what you are trying to achieve? I'm not sure what you mean by "set environment variables in Pyramid".

    Thanks,

    Ian

    • Nadav
    • 3 days ago
    • Reported - view

    Hi  . You can write code in a python ETL node that creates an environment variable. If you make it persistant (like on windows, using the setx command) than theoretically you can use it from other python nodes and/or on following runs. BUT, because pyramid is multi-server, if you have multiple DSML servers (our services that run python), then when you set an environment variable, it will only be set on one machine, and not on all the rest. 

    It is advised to use ETL variables instead. You can set those variables' values through a masterflow node, or you can store their values in a table using the ETL, and then setup the variables to be query based. This way you can practically set them from python. Then in python you can use @varname inside python to access the variables values.

     

    Here is a dummy example of how to achieve it. First go to the master flow, set up a variable (mine is named xxx), and then set a value for it in the masterflow:

    In my example the value is hard coded but it doesn't have to be. Please read more about ETL variables. Then in python code i can use the value of the variable:

     

     

    In this example i'm taking a table in python, adding a column that only has the variable's value, and saving it into a different db. This is better in the context of pyramid than environment variables, because the ETL variables will persist across multiple machines which makes the solution scalable.

    That said, if you really want, and only have one machine for the DSML server, you can set up and read environment variables in python like you would outside of pyramid.

Content aside

  • 1 Likes
  • 3 days agoLast active
  • 4Replies
  • 46Views
  • 4 Following