Issue tying to read environment variable in Python - python-3.x

Hi I'm trying to read an environment variable in python, if I execute my script from console with:
python3 myScript.py everything goes ok, but I need to run this script as a service in Ubuntu, in this case, the script can't get the environment variable. Anyone has past for the same issue? I noticed that when i'm trying to read the mongo URI from environment.

The correct way to achieve that is passing the environment variable or environment file to the service file, in my case I added this line to my service file:
EnvironmentFile = /etc/environment

Related

How to set environment path to folder in my documents directory on mac

Hello I am working on a hyper ledger fabric project using python
I am running into an error on my program which requires me to set an environment path
below is the error given :
configtxgen not in PATH.
Configtx is empty
now I know the fix for this, it requires me setting an environment path to a file called
configtx.yaml
its location on my Mac is
documents/blockchain/fabric-sdk-py/test/fixtures/e2e_cli/configtx.yaml
please how do I set an environment path towards this file
Thanks
How you set an env var depends on your shell and whether you are running the program from a shell prompt or some other way (e.g., double-clicking on an application icon). Assuming you're using a POSIX shell like bash or zsh you would type something like this:
export VAR_NAME="$HOME/documents/blockchain/fabric-sdk-py/test/fixtures/e2e_cli/configtx.yaml"
You would normally put that statement in a file like ~/.bashrc so it is set each time you start an interactive shell.
P.S., If the documentation for the application you're using doesn't tell you how to do this I would open an issue suggesting such instructions be added.

Why am I not able to receive output when running python code in VSCode?

I have tried to print simple messages like "Hello World!" but have always been met with: [Running] python -u "/Users/user/HelloWorld!!/app.py"
/bin/sh: python: command not found
[Done] exited with code=127 in 0.176 seconds
enter image description here
Is there any way to get passed this error?
Check environment variable PATH
Every time you as a user run a command on your console, the machine looks for its location, or address, inside a list of predefined directories that are stored inside the environment variable PATH.
Such design helps to properly run the program or command without having to specify the absolute path on the terminal.
The environment variable PATH can be modified temporarily for the current terminal session, or permanently.
For windows/mac/linux
AND
Go to the VS Code preferences, and under interpreter, you'll find Interpreter Path, so set that to the path of your python installation, restart VS Code, and you should be good.

Monit not invoking python script <--> OS is CentOS

Monit not invoking python script <--> OS is CentOS. first line in python script is "#!/usr/bin/env python3" when i tried to invoke python script from my terminal its working but monit is not able to trigger the script.
I tried to call python script from shell script in monit but no luck. even i tried adding PATH variable as second line to shell script.
any help will be appreciated.
Issue is with PATH environmental variable, like cron, monit is only taking subset of values from PATH variable instead of all values. So after explictly adding $PATH variable after shell interpreter, issue got resolved

Node process.env variables loaded from env.sh

I know that you can use a library dotenv to set process.env variables when writing an express app, but at work I use Python and we regularly use shell scripts (env.sh for example) to set environmental variables, especially locally.
So I wrote and then sourced an env.sh script to get credentials for my mongo database but I noticed something strange. When I defined the variables in env.sh, I defined them like so:
#env.sh
export username=blahbblahblah
export password=blahblahbalbha
Then I ran
source env.sh
I checked env and saw the variables listed as expected. But then I entered node and I saw the variables listed in process.env as
user=blablabhablabha\n
password=blabhalbhabl\n
So my question is, why does node include the newline character when bash linux doesn't? It must be that newline in the env.sh file, because I was able to fix this issue by writing my script as follows:
export username=blabhablha; export password=blabhalbahbal;

Nodejs module oracled cannot find LD_LIBRARY_PATH

I'm getting the following error in my nodejs script using the oracledb module on a Centos 6 VM:
Error: libclntsh.so.11.1: cannot open shared object file: No such file or directory
We're using the full Oracle client. My google searches have led me to LD_LIBRARY_PATH being the problem. It is set in /etc/profile.d/ in an oracle script, and I can see it in my linux user's env output. But when I check process.env within the node script, LD_LIBRARY_PATH is simply not there. (If I add other variables to my /etc/profile.d script, those test variables appear in process.env)
The other weirdness is that when I run the script as root, the variable gets set properly and the script executes as expected.
So why is LD_LIBRARY_PATH disappearing when my non-root user runs the script?
You didn't explain how you are invoking the script. If you are sudo-ing, do you need to call a shell script that sets LD_LIBRARY_PATH before invoking node?

Resources