4

How can I define .pdbrc on my Windows machine?

My .pdbrc file:

alias sl s;;l
alias nl n;;l
alias cl c;;l

After reading the answer to this question, I tried putting it in C:\Users\<my_user>. Starting pdb (using pdb.set_trace()), I tried the aliases. They weren't recognized.

I'd like to know how to set a .pdbrc both globally, and for a virtual environment.

Community
  • 1
  • 1
Aviv Cohn
  • 15,543
  • 25
  • 68
  • 131
  • what does `import os; print(os.path.abspath(os.path.expanduser('~')))` give you? Also, how about your `HOME` env var? Presumably they're the same... – Wayne Werner Feb 05 '16 at 17:19
  • @WayneWerner I don't have a `HOME` environment variable. Is it present on Windows machines by default? – Aviv Cohn Feb 05 '16 at 17:27
  • @WayneWerner Anyway, I just created it and set it to `C:\Users\`. The Python expression you gave prints out the same result. Still, `.pdbrc` doesn't work. – Aviv Cohn Feb 05 '16 at 17:31
  • @WayneWerner My bad, after restarting `cmd.exe` the aliases now work! Guess I needed to set the `HOME` environment variable. Want to post this as an answer? Thanks – Aviv Cohn Feb 05 '16 at 17:33
  • 2
    This should be fixed in pdb. It's [checking `HOME`](https://hg.python.org/cpython/file/v2.7.11/Lib/pdb.py#l76) instead of using the cross-platform alternative, `os.path.expanduser('~')`. – Eryk Sun Feb 06 '16 at 14:57
  • As a followup note -- some users appear to have `HOME` set as a system-level environment variable equal to `%HOMEDRIVE%%HOMEPATH%`. On Windows 10, this expands as desired for the current user, but on Win 7 (at least with default configuration, it does not, presumably because system env vars must all be defined before user ones, so this can't be expanded. Obviously if it doesn't expand then the user's .pdbrc won't be found. – Jonathan March Nov 21 '16 at 20:35

1 Answers1

1

pdb looks for the HOME system variable which is not defined by default in Windows. You have to define it yourself.

This issue arises because every user in a *nix operating system (Linux, Unix, Darwin, etc.) has a /home directory where they can put run codes like .pdbrc. The path to this directory lives in a system variable (HOME) that applications use to point to a user's personal files. Windows doesn't really have anything like that. The closest analogy to /home on Windows is probably C:\Users\<username>.

Here is how to define a HOME system variable that contains the path C:\Users\<username>. Left click on the startup button and then right click on "Computer" and select "Properties".

Click the startup menu > right click "Computer" > select "Properties"

On the top left, click the "Advanced system settings" link.

Click advanced system settings

This brings up the "System Properties" dialog. On the "Advanced" tab, press the "Environment variables..." button.

Click the "Environment Variables..." button

This brings up the "Environment Variables..." dialog. In the top section for "User variables for <username>", press the "New..." button.

Press "New..." in the User Variables section

For "Variable name:" put "HOME" and for "Variable value:" put C:\Users\<username>.

Enter "HOME" and path to what you want HOME to be

If a HOME variable already exists, just put a semi-colon between whatever is the current value and the new path. When an application uses the HOME variable, it will likely search the contents sequentially. If you want your new path to be found first, put it first in the list.

Hit "Okay" a bunch and then restart whatever application (cmd.exe or otherwise) is running pdb. Make sure that your .pdbrc file is in C:\Users\<username>. When you run pdb again, it should now read your .pdbrc file on startup.

Lorem Ipsum
  • 4,020
  • 4
  • 41
  • 67