# System environmental variable issue

**URL:** <https://travis-ci.community/t/system-environmental-variable-issue/12685>\
**Category:** Travis CI Discussions & Feedback\
**Created:** [February 16, 2022, 3:37am UTC](https://travis-ci.community/t/system-environmental-variable-issue/12685 "2022-02-16T03:37:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rl-mm](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/rl-mm/32/7687_2.png) [@rl-mm](https://travis-ci.community/u/rl-mm)\
**Post date:** [February 16, 2022, 3:37am UTC](https://travis-ci.community/t/system-environmental-variable-issue/12685/1 "2022-02-16T03:37:27Z")

</div>

I have a system environmental variable for Box on my computer called SHAREDDIR  
This is called in my scripts as SHAREDDIR = os.getenv(‘SHAREDDIR’) and used subsequently to access different files.  
However, my build always fails with Travis.

\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ ERROR collecting test\_blackboard.py \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
test\_blackboard.py:16: in  
if os.environ[‘SHAREDDIR’]:  
…/…/…/virtualenv/python3.7.1/lib/python3.7/os.py:678: in **getitem**  
raise KeyError(key) from None  
E KeyError: ‘SHAREDDIR’

I believe Travis cannot access that folder even though I import the os package initially.  
Any help with this will be greatly appreciated. Thank you.

---

<div class="post-metadata">

**Author:** ![Montana](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/montana/32/9566_2.png) [@Montana](https://travis-ci.community/u/Montana)\
**Post date:** [February 16, 2022, 6:32am UTC](https://travis-ci.community/t/system-environmental-variable-issue/12685/2 "2022-02-16T06:32:00Z")

</div>

Hey @ri-mm,

Can I see your `.travis.yml`?

---

<div class="post-metadata">

**Author:** ![rl-mm](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/rl-mm/32/7687_2.png) [@rl-mm](https://travis-ci.community/u/rl-mm)\
**Post date:** [February 16, 2022, 4:14pm UTC](https://travis-ci.community/t/system-environmental-variable-issue/12685/5 "2022-02-16T16:14:27Z")

</div>

language: python  
python:

- “3.7”  
arch: arm64

env:

- SHAREDDIR=os.getenv('SHAREDDIR)  
install:
- pip install -r requirements.txt

before\_script:

- touch .env

script: pytest

---

<div class="post-metadata">

**Author:** ![Montana](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/montana/32/9566_2.png) [@Montana](https://travis-ci.community/u/Montana)\
**Post date:** [February 17, 2022, 6:49pm UTC](https://travis-ci.community/t/system-environmental-variable-issue/12685/6 "2022-02-17T18:49:58Z")

</div>

Hey @rl-mm,

I suggest you check the environment in question for the existence of a variable, say in your case `"SHAREDDIR"`, in Python. One way you could achieve this is by doing:

```python
if os.getenv("SHAREDDIR") is not None:
    pass

```

It seems like you’re trying to see if something is present _in_ `environ` , why would you _get_ just to compare it and then _toss it away_ ?

That’s exactly what `getenv` does. Either way, `getenv` is just a wrapper around `environ.get`. So I don’t quite understand what you’re doing. Can you give me your GitHub handle so I can look at the project in it’s entirety?
