Skip to content

Question about enviromental variables #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
petobens opened this issue Jan 31, 2015 · 20 comments
Closed

Question about enviromental variables #48

petobens opened this issue Jan 31, 2015 · 20 comments

Comments

@petobens
Copy link

I've installed winpython today and I have a doubt about setting environmental variables. I understand that winpython aims to be a portable distribution but I wanted to be able to run python code from the cmd.exe and also use vim. So I've added the following directories to my %PATH%:

C:\winpython\python-3.4.2.amd64;C:\winpython\python-3.4.2.amd64\Scripts;C:\winpython\python-3.4.2.amd64\DLLs;C:\winpython\python-3.4.2.amd64\Lib

Now I can run scripts from the regular command prompt but I'm not sure that what I've done is correct. Is there an automatic way of setting the path (I've registered the distribution but the path was not modified)? Should I add more directories besides the mentioned ones?

Strangely I can run vim from WInPython CommandPrompt but not from the regular cmd.exe (when using the official python distribution I could run vim from command prompt without problem). This leads me to believe that I might be missing something. Any help and guidance will be appreciated. Thanks in advance!

@stonebig
Copy link
Contributor

Hi @petobens ,

You should have an example script in your

c:\winpython\scripts\env.bat

You can also launch

c:\winpython\scripts\cmd.bat

to get a dos windows with the previous script executed.

@petobens
Copy link
Author

Hi @stonebig , thanks for the quick reply. Let me first apologize for the fact that my following question is quite elementary but I can't get this to work. I want to permanently alter the %PATH%, adding the directories in env.bat. If I run env.bat I believe this will modifiy the %PATH temporarily because if after running the batch file I close the cmd.exe and re open it an run python I get the error saying it is not recognized as an internal command.
So my question is: how do I permanently add to the %PATH% the same directories that env.bat adds temporarily?
Once again sorry for the inconvenience and thanks for the help.

@stonebig
Copy link
Contributor

well,
looking at http://stackoverflow.com/questions/8358265/how-to-update-path-variable-permanently-from-cmd-windows

There is them manual change of the path method, described here:
http://geekswithblogs.net/renso/archive/2009/10/21/how-to-set-the-windows-path-in-windows-7.aspx#540517

Or there is this method, that I didn't try

rem (call winpython\script\cmd.bat, to launch the env.bat and have the dos command prompt)
rem then try this (from https://technet.microsoft.com/en-us/library/cc755104.aspx)
setx MYPATH %PATH%

Does anyone of this fit your problem ?

@petobens
Copy link
Author

petobens commented Feb 2, 2015

@stonebig thanks for the references. I was able to set the user variable using the method described by the SO question (unfortunately I still have to set system variables manually because the /M flag suggested in SO doesn't seem to work at least in my case). Since you include the possibility to register the distribution and state that:

these actions are exactly the same as those performed when installing Python with the official installer for Windows

and since the official installer gives the user the option (during installation) to automatically add the python executable to the %PATH% variable I was wondering if you could also add this option for winpython.

One last question: I installed jedi with by doing pip install jedi, however jedi is not listed in the uninstall package list of the WinPython Control Panel. Is this correct?

One again thanks for the help!

@stonebig
Copy link
Contributor

stonebig commented Feb 2, 2015

Yes, packages are listed only if you use WinPython Control Panel.exe

You can do pip uninstall jedi then re-install it via WinPython Control Panel.exe if you want to see it in WinPython Control Panel.

@petobens
Copy link
Author

petobens commented Feb 2, 2015

Thanks for clarifying that point. Regarding my other question, will you consider adding an option to automatically add python to the path from within the winpython control panel (something the official python offers during installation ) ? Or do you want me to close this issue?

@stonebig
Copy link
Contributor

stonebig commented Feb 2, 2015

I didn't have time to think about that part of winpython yet, so I have no opinion. You can keep it open.

@petobens
Copy link
Author

petobens commented Feb 3, 2015

Ok. Thanks again for the help.

@ankostis
Copy link

ankostis commented Feb 6, 2015

+1 for @petobens proposal for adding WinPython in PATH, since without it, python-packages requiring DLLs fail.

Related to #28

@luigibrosse
Copy link

Hi, I would like to see something like this as well. It is quite tedious to manually insert / update python in the PATH each time that I move from one version of winpython to the next. Please consider it.

@yw5aj
Copy link
Contributor

yw5aj commented Apr 4, 2015

Being curious - is it that we are planning to do this in the future via changing the windows registry (http://stackoverflow.com/questions/2121795/programmatically-modifiy-environment-variables), or are we holding this off because chaning the registry will cause other bugs?

PS: remember that we need to change HOME to settings dir as well... It's probably just me but I missed it earlier today.

@petobens
Copy link
Author

petobens commented Apr 4, 2015

PS: remember that we need to change HOME to settings dir as well... It's probably just me but I missed it earlier today.

@yw5aj if I change/create a HOME env variable and set it to the settings dir then when I fire up from the cmd prompt a program that requires python, such asvim, such program doesn't know where to find its config file,vimrc, which lives in the %USERPROFILE% directory (in my case, C:\Users\Pedro).

The only way I found to get gvim (not vim) to work is to create a PYTHONHOME env variable set to C:\winpython\python-3.4.3.amd64. Your solution allows vim to work but I have no idea how to have it working and also loading the correct config file from my %USERPROFILE% directory.

I don't know what the standard python installation does but when I chose to add python to the path then I could use both vim and gvim without problems (i.e loading the correcting config file).

Maybe this link is relevant.

EDIT: I don't use vim in the cmd prompt and I therefore don't mind it doesn't work there. What I do want to point out that in order to use gvim I had to set explicitly the PYTHONHOME variable (whereas with the official python installer there is no need to do this).

@yw5aj
Copy link
Contributor

yw5aj commented Apr 5, 2015

@petobens Thanks! That's a good point. It almost look like that we want this:

When installing/configuring WinPython, we can select a irreversible option about whether to move the settings folder to the system %USERPROFILE% directory.

Not sure whether we'd like to do that, but that would solve the gvim issue (just an example) I guess?

Shawn

@petobens
Copy link
Author

@yw5aj sorry for the late reply.

I don't know if the solution is to move the settings folder to the home directory (if I do that I believe that I can't open gvim or vim from the standard cmd prompt).

What I (and others) want is just to have the option to add Winpython to the path env variable during installation (the way the regular python installer does). Hope @stonebig can implement this wanted feature.

@stonebig
Copy link
Contributor

I still don't have a strong opinion on this and feel technically uncomfortable.

@petobens
Copy link
Author

Okay. No Problem! Thanks for the quick reply.

@ankostis
Copy link

Dear @stonebig I receive at least once a month an "angry" request from people that i have recommended them using WinPython due to this issue.

The sequence of events is like this:

  1. They want to run a python project of mine with native libs and DLLs (i.e. numpy & win32api).
  2. I tell them "install WinPython and don't forget to manually update your PATH" .
  3. They fail to do it :-) and i help them over the phone into achieving the above task.
  4. Months later, when they upgrade their WinPython (i.e. to get more recent pandas).
  5. THEY FORGET TO FIX THE PATH.
  6. After days of trying to fix it, they come back shouting at me that my code is broken!

So, would it be possible to fix this once and for all?
It should have little to do with HOME and Settings.

@ankostis
Copy link

My suggestion of how this capability should work is this:

A) The WinPython-installer on start-up checks existing PATH for locating a (win)python.exe.

B.a) If python.exe exists in PATH, it provides the user with this choice:

Update python-X.Y.V --> Python-XX.YY.ZZ into your PATH environment variable ?

and possibly add another one, whether to try and set this for all users).

B.b) Otherwise, if no python.exe exists in PATH, the choice should read:

Add python-X.Y.V into your PATH environment variable?

C. Before exiting installer, if user had checked the above options, it will:

  • i) gather all path-elements containing the identified (win)python.exe.
  • ii) Construct a setx PATH=... batch-script to prepend PATH with the new python (or use win32api registry-code) and
  • iii) (depending on the 2nd choice) try running this with admin-rights or failback updating user-path env-var only.

I still have one issue unresolved, what to do if a python.exe from a different distribution is found (ie from cygwin or anaconda).

@stonebig
Copy link
Contributor

Hi @ankostis,

What you suggest doesn't look a good idea to me.

Maybe Winpython is not currently the right solution for your users / your use case.

I didn't try it myself but maybe, maybe, pyzo would better fit your particular need ?

@stonebig
Copy link
Contributor

stonebig commented May 4, 2025

I would think that the problem is nowodays solved per tweaking ./settings/winpython.ini
re-open if not.

@stonebig stonebig closed this as completed May 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants