Data Science Skills

We create high quality open lessons for open science.

Tips and tricks for checking your Python Environment

February 12, 2023 | 2 min Read

We’ve all been there… trying to import a package and python can’t find it? Below are a few tricks to figure out what environment you are in!

This can be useful when troubleshooting code that is not running as you expect!

Tips and tricks

this is a good trick for when you’re working in Python and something seems wrong with your environment. It could be that you are in a different environment than you think you are!

Python to the rescue!

The code snippet below will print the conda environment name to help you troubleshootz.

import os

# print(os.environ['CONDA_DEFAULT_ENV'])
os.environ.keys
<bound method Mapping.keys of environ({'CI': 'true', 'CONDA_DIR': '/opt/conda', 'DENO_DOM_PLUGIN': '/opt/quarto/bin/tools/deno_dom/libplugin.so', 'DENO_NO_UPDATE_CHECK': '1', 'GITHUB_ACTION': '__run_5', 'GITHUB_ACTIONS': 'true', 'GITHUB_ACTION_REF': '', 'GITHUB_ACTION_REPOSITORY': '', 'GITHUB_ACTOR': 'lwasser', 'GITHUB_ACTOR_ID': '7649194', 'GITHUB_API_URL': 'https://api.github.com', 'GITHUB_BASE_REF': '', 'GITHUB_ENV': '/__w/_temp/_runner_file_commands/set_env_7ce832b8-08de-4a12-adee-7e4ab4178675', 'GITHUB_EVENT_NAME': 'push', 'GITHUB_EVENT_PATH': '/github/workflow/event.json', 'GITHUB_GRAPHQL_URL': 'https://api.github.com/graphql', 'GITHUB_HEAD_REF': '', 'GITHUB_JOB': 'build-website', 'GITHUB_OUTPUT': '/__w/_temp/_runner_file_commands/set_output_7ce832b8-08de-4a12-adee-7e4ab4178675', 'GITHUB_PATH': '/__w/_temp/_runner_file_commands/add_path_7ce832b8-08de-4a12-adee-7e4ab4178675', 'GITHUB_REF': 'refs/heads/main', 'GITHUB_REF_NAME': 'main', 'GITHUB_REF_PROTECTED': 'false', 'GITHUB_REF_TYPE': 'branch', 'GITHUB_REPOSITORY': 'data-science-skills/dss-web', 'GITHUB_REPOSITORY_ID': '600898590', 'GITHUB_REPOSITORY_OWNER': 'data-science-skills', 'GITHUB_REPOSITORY_OWNER_ID': '125224243', 'GITHUB_RETENTION_DAYS': '90', 'GITHUB_RUN_ATTEMPT': '1', 'GITHUB_RUN_ID': '8055287413', 'GITHUB_RUN_NUMBER': '114', 'GITHUB_SERVER_URL': 'https://github.com', 'GITHUB_SHA': '3a07e29595e935f0ba8afe8504c1420bb6174e9d', 'GITHUB_STATE': '/__w/_temp/_runner_file_commands/save_state_7ce832b8-08de-4a12-adee-7e4ab4178675', 'GITHUB_STEP_SUMMARY': '/__w/_temp/_runner_file_commands/step_summary_7ce832b8-08de-4a12-adee-7e4ab4178675', 'GITHUB_TRIGGERING_ACTOR': 'lwasser', 'GITHUB_WORKFLOW': 'Build DSS website', 'GITHUB_WORKFLOW_REF': 'data-science-skills/dss-web/.github/workflows/build-site.yml@refs/heads/main', 'GITHUB_WORKFLOW_SHA': '3a07e29595e935f0ba8afe8504c1420bb6174e9d', 'GITHUB_WORKSPACE': '/__w/dss-web/dss-web', 'GOLANG_ARCH': 'amd64', 'GOLANG_OS': 'linux', 'GOLANG_VERSION': '1.17', 'HOME': '/github/home', 'HOSTNAME': 'bd1e561f743c', 'LANG': 'C.UTF-8', 'LC_ALL': 'C.UTF-8', 'MPLBACKEND': 'module://matplotlib_inline.backend_inline', 'PATH': '/__t/node/18.19.1/x64/bin:/opt/conda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/go/bin', 'PWD': '/__w/dss-web/dss-web', 'QUARTO_BIN_PATH': '/opt/quarto/bin', 'QUARTO_DENO': '/opt/quarto/bin/tools/deno-x86_64-unknown-linux-gnu/deno', 'QUARTO_FILTER_DEPENDENCY_FILE': '/tmp/quarto-session991a162f/ab592a66/a425388a', 'QUARTO_PROFILE': '', 'QUARTO_PROJECT_DIR': '/__w/dss-web/dss-web', 'QUARTO_ROOT': '/', 'QUARTO_SHARE_PATH': '/opt/quarto/share', 'RUNNER_ARCH': 'X64', 'RUNNER_ENVIRONMENT': 'github-hosted', 'RUNNER_NAME': 'GitHub Actions 7', 'RUNNER_OS': 'Linux', 'RUNNER_TEMP': '/__w/_temp', 'RUNNER_TOOL_CACHE': '/__t', 'RUNNER_WORKSPACE': '/__w/dss-web', 'SHLVL': '2', '_': '/opt/quarto/bin/tools/deno-x86_64-unknown-linux-gnu/deno', 'QUARTO_FIG_WIDTH': '8', 'QUARTO_FIG_HEIGHT': '5', 'QUARTO_FIG_DPI': '192', 'QUARTO_FIG_FORMAT': 'png', 'PYDEVD_USE_FRAME_EVAL': 'NO', 'JPY_PARENT_PID': '1180', 'TERM': 'xterm-color', 'CLICOLOR': '1', 'FORCE_COLOR': '1', 'CLICOLOR_FORCE': '1', 'PAGER': 'cat', 'GIT_PAGER': 'cat'})>

…when you are developing tools you may want to make sure your package is installed in editable mode…

Leah Wasser

Leah Wasser

Leah is the executive director of pyOpenSci .