0

I've written a python application which can be set in development or production mode by using an environment variable. This variable can be passed as a CLI argument:

 if len(argv) >= 2:
 environ['DISCOVERY_ENV'] = argv[1]
 else:
 environ['DISCOVERY_ENV'] = 'development'

The problem now is that this environment is not being set. Which means if I've following code, it doesn't work:

if environ.get('DISCOVERY_ENV') == 'production':
 import adafruit_ads1x15.ads1015 as ADS
 from adafruit_ads1x15.analog_in import AnalogIn
 import busio
 import board

In this example the libraries will not being imported.

EDIT:

This does work on Windows but not on linux, my case: Rasbian OS.

Does anyone know why this doesn't work?

Thanks in advance!

asked Dec 21, 2020 at 14:15
2
  • What happens if you try to print your environ.get('DISCOVERY_ENV')? Commented Dec 21, 2020 at 14:28
  • @BriseBalloches It returns None. Commented Dec 21, 2020 at 14:30

1 Answer 1

1

By looking at your code, I think you are on micropython. If this is the case, according to the doc, environ is not implemented yet.

By quoting the doc, the suggestion seems to be the following:

Workaround: Use getenv, putenv and unsetenv

answered Dec 21, 2020 at 14:23

5 Comments

Hi, im using Python 3.6 which comes with raspberry. I don't think this is MicroPython. But anyway using getenv and putenv didn't solve the problem.
Oh I'm sorry, if so I'll check if any other idea comes to my mind. Sadly, I'm not able to reproduce the issue. Maybe the answer provided here can be helpful to you?
I added to the question the fact that the problem is on linux only. On windows this works perfect. Thats why I'm confused. But I'll go and check out the link you gave me.
What happens if you use environ['DISCOVERY_ENV'] = "test" print(environ.get('DISCOVERY_ENV')) ? I mean, in the same .py script, just to check if there is an issue that's not on python side. For example it could happens that the first portion of your code and the second ones belongs to 2 different python files and they are executed in a different context.
The problem wasn't on the environ side, it was on how I tried to import the dependecies which don't work that way. Thank you very much for helping

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.