question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PYTHONPATH not set when running profiler

See original GitHub issue

Issue Report Checklist

  • Searched the issues page for similar reports
  • Read the relevant sections of the Spyder Troubleshooting Guide and followed its advice
  • Reproduced the issue after updating with conda update spyder (or pip, if not using Anaconda)
  • Could not reproduce inside jupyter qtconsole (if console-related)
  • Tried basic troubleshooting (if a bug/error)
    • Restarted Spyder
    • Reset preferences with spyder --reset
    • Reinstalled the latest version of Anaconda
    • Tried the other applicable steps from the Troubleshooting Guide
  • Completed the Problem Description, Steps to Reproduce and Version sections below

Problem Description

It seems like the PYTHONPATH set in Spyder is not used when profiling. This causes a bit of issues if one is profiling library code.

Except for the behavior not being as expected, the following code:

import os
try:
    user_paths = os.environ['PYTHONPATH'].split(os.pathsep)
except KeyError:
    user_paths = []
print(user_paths)

results in [] in the profiler output (despite PYTHONPATH being non-empty in the dialog).

Maybe related to: #12564 #9388 #3161 (I commented there as well, but not sure it is the same problem).

What steps reproduce the problem?

  1. Add a module to PYTHONPATH in the Spyder dialog
  2. Profile code that relies on that module

What is the expected output? What do you see instead?

That the PYTHONPATH is set in the profiler.

Paste Traceback/Error Below (if applicable)


PASTE TRACEBACK HERE

Versions

  • Spyder version: 4.1.5 and 5.0.0.dev0 62e0dfe
  • Python version: 3.7.9 64-bit
  • Qt version: 5.9.6
  • PyQt5 version: 5.9.2
  • Operating System: Windows 10

Dependencies


# Mandatory:
atomicwrites >=1.2.0        :  1.4.0 (OK)
chardet >=2.0.0             :  3.0.4 (OK)
cloudpickle >=0.5.0         :  1.6.0 (OK)
cookiecutter >=1.6.0        :  1.7.2 (OK)
diff_match_patch >=20181111 :  20200713 (OK)
intervaltree                :  None (OK)
IPython >=4.0               :  7.18.1 (OK)
jedi =0.17.2                :  0.17.2 (OK)
nbconvert >=4.0             :  6.0.7 (OK)
numpydoc >=0.6.0            :  1.1.0 (OK)
paramiko >=2.4.0            :  2.7.2 (OK)
parso =0.7.0                :  0.7.0 (OK)
pexpect >=4.4.0             :  4.8.0 (OK)
pickleshare >=0.4           :  0.7.5 (OK)
psutil >=5.3                :  5.7.2 (OK)
pygments >=2.0              :  2.7.1 (OK)
pylint >=1.0                :  2.6.0 (OK)
pyls >=0.35.0;<1.0.0        :  v4.0.0b2+5278.g62e0dfe (OK)
qdarkstyle >=2.8            :  2.8.1 (OK)
qtawesome >=0.5.7           :  1.0.1 (OK)
qtconsole >=4.7.7           :  4.7.7 (OK)
qtpy >=1.5.0                :  1.9.0 (OK)
rtree >=0.8.3               :  0.9.4 (OK)
sphinx >=0.6.6              :  3.2.1 (OK)
spyder_kernels >=2.0.0dev0  :  2.0.0.dev0 (OK)
watchdog                    :  None (OK)
zmq >=17                    :  19.0.2 (OK)

# Optional:
cython >=0.21               :  0.29.21 (OK)
matplotlib >=2.0.0          :  3.3.1 (OK)
numpy >=1.7                 :  1.19.1 (OK)
pandas >=1.1.1              :  1.1.3 (OK)
scipy >=0.17.0              :  1.5.2 (OK)
sympy >=0.7.3               :  1.8.dev (OK)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ccordoba12commented, Oct 20, 2020

Hey @oscargus, thanks for reporting. I know what’s happening in this case and we’ll fix the underlying problem in our next version (4.2.0) to be released in November.

For now, I think you can avoid it by dropping PYTHONPATH from the terminal where you plan to start Spyder.

0reactions
ccordoba12commented, Feb 11, 2021

No, there’s no workaround and the profiler is using the same interpreter that Spyder is running on.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Permanently add a directory to PYTHONPATH? - Stack Overflow
On Windows, with Python 2.7 go to the Python setup folder. · Open Lib/site-packages. · Add an example.pth empty file to this folder....
Read more >
Using PYTHONPATH — Functional MRI methods
PYTHONPATH is an environment variable. See the Python 3 docs for PYTHONPATH. The PYTHONPATH variable has a value that is a string with...
Read more >
The initialization of the sys.path module search path — Python ...
A module search path is initialized when Python starts. This module search path may be accessed at sys.path. The first entry in the...
Read more >
How do I set PYTHONPATH and other environment variables ...
If you are not seeing the desired settings, try running 'ipython' at the command prompt to see if it reports any issues. As...
Read more >
Setting Your PYTHONPATH environment variable (Linux/Unix ...
If you do not have a PYTHONPATH set up yet you can simply copy the one ... them to be called by any...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found