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

Native virtualenv support for shell configurations #403

Closed
jpauwels opened this Issue Jun 20, 2016 · 10 comments

Comments

Projects
None yet
4 participants
@jpauwels

jpauwels commented Jun 20, 2016

It would be nice if Pyzo would support virtualenv. I can recreate some functionality by using the Python binary inside the virtualenv and modifying the pythonpath, but it would be better if the corresponding activate script was sourced.

@almarklein

This comment has been minimized.

Show comment
Hide comment
@almarklein

almarklein Jun 23, 2016

Collaborator

I don't have a lot of experience using virtual env. If you have a good idea how this can be made to work, I'd welcome a pull request :)

Collaborator

almarklein commented Jun 23, 2016

I don't have a lot of experience using virtual env. If you have a good idea how this can be made to work, I'd welcome a pull request :)

@Sekuraz

This comment has been minimized.

Show comment
Hide comment
@Sekuraz

Sekuraz Dec 16, 2016

The activate script only sets environment variables, but i have no idea how to pass them to the shell process in pyzo.

Sekuraz commented Dec 16, 2016

The activate script only sets environment variables, but i have no idea how to pass them to the shell process in pyzo.

@almarklein

This comment has been minimized.

Show comment
Hide comment
@almarklein

almarklein Dec 19, 2016

Collaborator

Each shell config has a field for environment variables. E.g. in the logger shell you can type pyzo.config.shellConfigs2[0].environ. The corresponding code for the shell config dialog is here; it's a newline-separated list of assignments.

Collaborator

almarklein commented Dec 19, 2016

Each shell config has a field for environment variables. E.g. in the logger shell you can type pyzo.config.shellConfigs2[0].environ. The corresponding code for the shell config dialog is here; it's a newline-separated list of assignments.

@lcerman

This comment has been minimized.

Show comment
Hide comment
@lcerman

lcerman Feb 3, 2017

Contributor

I just started using virtualenv and hit the similar problem. To my understanding, the virtualenv activate script just sets:

VIRTUAL_ENV="/path/to/venv"
export VIRTUAL_ENV

PATH="$VIRTUAL_ENV/bin:$PATH"
export PATH

(in fact it does more fancy stuff to unset those variables when deactivating the env, which is not important here). Bottomline: I don't know what the VIRTUAL_ENV does and if it is really necessary... does anyone know if we need it?

So to mimic the same in Pyzo, all is needed is to set PATH to contain venv's bin directory. This can be done by filling the environ field of Shell config dialog. Then the exe filed in the shell config can be just python and it will exec the correct python from within the virtual env.

@jpauwels entering directly the full path of the python binary from withing the venv directly into the exe field without setting the PATH is cumbersome. E.g., if some of your libraries inside the venv launches another python script using /usr/bin/env python, which is more or less the normal way to do it, then it will actually launch the global python not the one in the venv.

@almarklein to allow extending the PATH variable from withing the environ field, I created #469, so one can fill in:

PATH=/path/to/venv/bin:$PATH

If others agree this is the correct solution for using virtualenv from within Pyzo I would be for noting this in the official documentation so it is easier do discover it for a user without the deeper knowledge of virtualenv internals.

Contributor

lcerman commented Feb 3, 2017

I just started using virtualenv and hit the similar problem. To my understanding, the virtualenv activate script just sets:

VIRTUAL_ENV="/path/to/venv"
export VIRTUAL_ENV

PATH="$VIRTUAL_ENV/bin:$PATH"
export PATH

(in fact it does more fancy stuff to unset those variables when deactivating the env, which is not important here). Bottomline: I don't know what the VIRTUAL_ENV does and if it is really necessary... does anyone know if we need it?

So to mimic the same in Pyzo, all is needed is to set PATH to contain venv's bin directory. This can be done by filling the environ field of Shell config dialog. Then the exe filed in the shell config can be just python and it will exec the correct python from within the virtual env.

@jpauwels entering directly the full path of the python binary from withing the venv directly into the exe field without setting the PATH is cumbersome. E.g., if some of your libraries inside the venv launches another python script using /usr/bin/env python, which is more or less the normal way to do it, then it will actually launch the global python not the one in the venv.

@almarklein to allow extending the PATH variable from withing the environ field, I created #469, so one can fill in:

PATH=/path/to/venv/bin:$PATH

If others agree this is the correct solution for using virtualenv from within Pyzo I would be for noting this in the official documentation so it is easier do discover it for a user without the deeper knowledge of virtualenv internals.

@lcerman

This comment has been minimized.

Show comment
Hide comment
@lcerman

lcerman Feb 3, 2017

Contributor

Sill some troubles there, need to do more testing, sorry. Let you know if I found a solution.

Contributor

lcerman commented Feb 3, 2017

Sill some troubles there, need to do more testing, sorry. Let you know if I found a solution.

@lcerman

This comment has been minimized.

Show comment
Hide comment
@lcerman

lcerman Feb 3, 2017

Contributor

OK everything is fine, it just showed that the VIRTUAL_ENV must be set too to have a proper virtualenv behavior. In my case not having it set broke the vext.pyqt4 package.

Contributor

lcerman commented Feb 3, 2017

OK everything is fine, it just showed that the VIRTUAL_ENV must be set too to have a proper virtualenv behavior. In my case not having it set broke the vext.pyqt4 package.

@almarklein

This comment has been minimized.

Show comment
Hide comment
@almarklein

almarklein Feb 6, 2017

Collaborator

I agree that it makes sense to make this the recommended way to do virtual envs in Pyzo. I will add a note in the docs / website.

Collaborator

almarklein commented Feb 6, 2017

I agree that it makes sense to make this the recommended way to do virtual envs in Pyzo. I will add a note in the docs / website.

@almarklein

This comment has been minimized.

Show comment
Hide comment
@almarklein

almarklein Feb 6, 2017

Collaborator

Added note in FAQ on website.

Collaborator

almarklein commented Feb 6, 2017

Added note in FAQ on website.

@almarklein almarklein closed this Feb 6, 2017

@lcerman

This comment has been minimized.

Show comment
Hide comment
@lcerman

lcerman Feb 6, 2017

Contributor

Nice. I would also recommend setting VIRTUAL_ENV in the FAQ:

VIRTUAL_ENV=/path/to/venv

Had some trouble not doing so as noted above.

Contributor

lcerman commented Feb 6, 2017

Nice. I would also recommend setting VIRTUAL_ENV in the FAQ:

VIRTUAL_ENV=/path/to/venv

Had some trouble not doing so as noted above.

@almarklein

This comment has been minimized.

Show comment
Hide comment
@almarklein

almarklein Feb 7, 2017

Collaborator

ah, I'll add it right now

Collaborator

almarklein commented Feb 7, 2017

ah, I'll add it right now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment