[Py] [Python Help] No able to activate a virtual env on pycharm

2024-10-11 Thread Luis Saavedra via Discussions on Python.org


Dear Python community.

the issue I am facing is i am not able to activate a virtual env. using Pycharm 
app. 


Please not the following:
1.  I have a folder with a project running python/Django, named 
“Production” copied in an external hard drive, the project folder was copied 
from a ubuntu server running in a primary testing server. 
2.  Then, I created and config a second testing server running the latest 
LTS Ubuntu version and install python, pycharm, Django, postgresql;
3.  Then I copied the project folder named “Production” I have in the 
external hard drive to the /home/user_folder/ folder location in Ubunto server. 
So, the route I copied the folder is the following /home/user_folder/Production.
4.  The folder “Production” had a folder name venv, what was the virtual 
environment on the primary testing server. But I renamed that folder to 
venv_old, to I created a new virtual env on second testing server,
5.  The new virtual env I created by clicking on pycharm “File” menu, then 
go to “Settings”, go to “Python Interpreter” and finally click on “Add 
Interpreter.”
6.  On the “Add Python Interpreter” windows I checked the checkbox “Inherit 
global site-packages”. You can refer to image below.
7.  Then a new venv folder was created inside the “Production” folder
8.  On the pycharm I go to terminal and navigate until the venv folder just 
created. Inside of it I have the bin folder and inside of it I have the 
activate filed, activate, activate.csh, activate.fish, activate.ps1, among 
other. 
9.  But when I run: ~/production$ venv/bin/activate the terminal shows a 
message Permission denied (commando Permissão negada)  since the server is 
setting in Portuguese.
10. But when I run ~/production$ venv/bin/activate the terminal shows a 
message command not found (commando não encontrado)  since the server is 
setting in Portuguese.
11. Note when I run $python3 --version, it shows  Python 3.12.3
12. When I run # pip --version, it shows  pip 24.0 from 
/user/lib/python3/dist-packages/pip (python3.12) 

I have no idea why I am getting the error “Command not found” when try to 
activate my virtual env. If someone can give me help, I will really appreciate. 
Thanks in advance. 



![Image (5)|666x500](upload://tUTfoMiNwaDRchEhcEOaYRxCg4g.jpeg)





---
[Visit 
Topic](https://discuss.python.org/t/no-able-to-activate-a-virtual-env-on-pycharm/67551/1)
 or reply to this email to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click 
here](https://discuss.python.org/email/unsubscribe/14b2b791d15cb69be4f56b1db82ec1ca2c14e46414daf9a1d313757a3ad1f395).


[Py] [Python Help] No able to activate a virtual env on pycharm

2024-10-11 Thread Alexander Bessman via Discussions on Python.org


The command to activate a venv is `source venv/bin/activate`.





---
[Visit 
Topic](https://discuss.python.org/t/no-able-to-activate-a-virtual-env-on-pycharm/67551/2)
 or reply to this email to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click 
here](https://discuss.python.org/email/unsubscribe/55a290fc42c0a51fb5d856f485ac2607a6a0418fabcd5729461c95dbea7a8b6e).


[Py] [Python Help] No able to activate a virtual env on pycharm

2024-10-11 Thread Luis Saavedra via Discussions on Python.org


thank you Alexander

I was so used to running it from powershell on windows, that I didn't use the 
source command.

Thank you so much





---
[Visit 
Topic](https://discuss.python.org/t/no-able-to-activate-a-virtual-env-on-pycharm/67551/3)
 or reply to this email to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click 
here](https://discuss.python.org/email/unsubscribe/7206633c0b65c7d6d76377babb5a7077e9b7332a2e704e3490a88774f036f9c6).


[Py] [Python Help] Venv: `activate` script changes `$PATH` while executing the binary doesn't

2024-10-11 Thread Clint Hepner via Discussions on Python.org


Still, it boils down to: whatever command `west` executes is either not found 
outside your virtual environment, or a different version exists outside it. 
Path lookup is not exclusive to the shell; `subprocess.run` *also* uses path 
lookup to find `command-provided-by-a-required-package`.





---
[Visit 
Topic](https://discuss.python.org/t/venv-activate-script-changes-path-while-executing-the-binary-doesnt/67580/4)
 or reply to this email to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click 
here](https://discuss.python.org/email/unsubscribe/8e095f1f5bf8a5f824a6b98e1799c6a2aa990ffe48c48e44dba1a42603027c21).


[Py] [Python Help] Venv: `activate` script changes `$PATH` while executing the binary doesn't

2024-10-11 Thread Jérôme Pouiller via Discussions on Python . org


But, the [documentation says][1]:

> Furthermore, all scripts installed in the environment should be runnable 
> without activating it.

My understanding is `/home/jerome/.local/pipx/venvs/west/bin/west` or `sh -c 
'source /home/jerome/.local/pipx/venvs/west/bin/activate; west'` should give 
the same result.

[1]: https://docs.python.org/3/library/venv.html#how-venvs-work





---
[Visit 
Topic](https://discuss.python.org/t/venv-activate-script-changes-path-while-executing-the-binary-doesnt/67580/5)
 or reply to this email to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click 
here](https://discuss.python.org/email/unsubscribe/ecae2372a4edb2e80459b2913c4bedbdd1c875eebf8600fc228fbcfb5c21e776).


[Py] [Python Help] Venv: `activate` script changes `$PATH` while executing the binary doesn't

2024-10-11 Thread James Parrott via Discussions on Python.org


It's expected behaviour.

To be able to run a command line tool globally, it could be installed with 
pipx.  Pipx'll put it in its own venv, and add the tool's executable to the 
global path.





---
[Visit 
Topic](https://discuss.python.org/t/venv-activate-script-changes-path-while-executing-the-binary-doesnt/67580/6)
 or reply to this email to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click 
here](https://discuss.python.org/email/unsubscribe/5e92f290d7564fe143ba665a7116c9d8aeb9d2f537c691d3cd2d1bd7c0509c19).


[Py] [Python Help] Venv: `activate` script changes `$PATH` while executing the binary doesn't

2024-10-11 Thread Jérôme Pouiller via Discussions on Python . org


I forgot to mention:

$ which west
/home/jerome/.local/bin/west
$ ls -l /home/jerome/.local/bin/west
lrwxrwxrwx 1 jerome jerome 44 Feb 22  2024 /home/jerome/.local/bin/west -> 
/home/jerome/.local/pipx/venvs/west/bin/west*

The issue is not about finding the `west` command by itself, but finding the 
commands run by `west`.





---
[Visit 
Topic](https://discuss.python.org/t/venv-activate-script-changes-path-while-executing-the-binary-doesnt/67580/3)
 or reply to this email to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click 
here](https://discuss.python.org/email/unsubscribe/8f63e8331331d80adb1f8eefd9538e1324339ac2b44c233a3905afadec3a4419).


[Py] [Python Help] Venv: `activate` script changes `$PATH` while executing the binary doesn't

2024-10-11 Thread Clint Hepner via Discussions on Python.org


[quote="Jérôme Pouiller, post:5, topic:67580, full:true, 
username:jerome-pouiller"]
But, the [documentation 
says](https://docs.python.org/3/library/venv.html#how-venvs-work):

> Furthermore, all scripts installed in the environment should be runnable 
> without activating it.

My understanding is `/home/jerome/.local/pipx/venvs/west/bin/west` or `sh -c 
'source /home/jerome/.local/pipx/venvs/west/bin/activate; west'` should give 
the same result.
[/quote]

That only applies to commands run directly from the shell.





---
[Visit 
Topic](https://discuss.python.org/t/venv-activate-script-changes-path-while-executing-the-binary-doesnt/67580/7)
 or reply to this email to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click 
here](https://discuss.python.org/email/unsubscribe/9df0854018af9fa5887b6725b161ccc4861eab382867cf230610bf151061934e).


[Py] [Python Help] Venv: `activate` script changes `$PATH` while executing the binary doesn't

2024-10-11 Thread Jérôme Pouiller via Discussions on Python . org


hmm... so the idea is "a python package should never call a binary provided by 
another package", that's it? Yet, I believe it is a common pattern.





---
[Visit 
Topic](https://discuss.python.org/t/venv-activate-script-changes-path-while-executing-the-binary-doesnt/67580/8)
 or reply to this email to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click 
here](https://discuss.python.org/email/unsubscribe/a8d6fb621757238213deaff5b8b1ba672a696db17dd7c3231c605eefb73ff389).


[Py] [Python Help] Venv: `activate` script changes `$PATH` while executing the binary doesn't

2024-10-11 Thread James Parrott via Discussions on Python.org


"Should" is a strong word.  Why not simply import the package and call the 
entry point directly?





---
[Visit 
Topic](https://discuss.python.org/t/venv-activate-script-changes-path-while-executing-the-binary-doesnt/67580/9)
 or reply to this email to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click 
here](https://discuss.python.org/email/unsubscribe/feda3e8602b5d5b33cc61f01773c831dd8800e21902146feac5bb673ef42f3f3).


[Py] [Python Help] Venv: `activate` script changes `$PATH` while executing the binary doesn't

2024-10-11 Thread Clint Hepner via Discussions on Python.org


No, the idea is that you write the Python code with enough information to 
*identify* the external binary, given a suitable execution environment. 
Ideally, you are going to execute the command by name alone, not an absolute or 
relative path, and configure the (virtual) environment so that the command is 
found in a directory on your `PATH`. You seem to have done that in your first 
two examples, but not in the third.





---
[Visit 
Topic](https://discuss.python.org/t/venv-activate-script-changes-path-while-executing-the-binary-doesnt/67580/10)
 or reply to this email to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click 
here](https://discuss.python.org/email/unsubscribe/35f328781814ffaad6c602910fd8ddc11a7a2ce58248f214254363f0b5801bc5).


[Py] [Python Help] Venv: `activate` script changes `$PATH` while executing the binary doesn't

2024-10-11 Thread Jérôme Pouiller via Discussions on Python . org


I spend a bunch of time to understand why one of my python command (`west`) 
didn't work as expected. Finally, I found it was because I installed my package 
in a `venv` and `west` it executed commands provided by required packages. eg:

import subprocess
subprocess.run(["command-provided-by-a-required-package"])

So, the snippet below worked:

$ source /home/jerome/.local/pipx/venvs/west/bin/activate
(west) $ west
...  ...

This one also worked:

$ export PATH=$PATH:/home/jerome/.local/pipx/venvs/west/bin
$ west
...  ...

But running `west` without changing the `$PATH` didn't work:

$ west
...  ...

(note since I have no luck, the error message was unrelated to `$PATH`)

I thought that running a binary from a `venv` had exactly the same behavior 
than activating the `venv` and then running the binary. The documentation seems 
to say the same. Do you think this behavior is a bug or is expected? If it is 
expected, what change should I suggest to `west` to properly run with `venv`?





---
[Visit 
Topic](https://discuss.python.org/t/venv-activate-script-changes-path-while-executing-the-binary-doesnt/67580/1)
 or reply to this email to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click 
here](https://discuss.python.org/email/unsubscribe/4ab79d6dc03448ad9d8a4eb449589328c2341222c2431963200d0321645cf726).


[Py] [Python Help] Venv: `activate` script changes `$PATH` while executing the binary doesn't

2024-10-11 Thread Clint Hepner via Discussions on Python.org


Your first two examples are equivalent; activating the virtual environment is 
done primarily to modify `PATH` in exactly the way you do so manually in your 
second example.

What happens when you (try to) execute `west` without modifying your `PATH` 
variable depends on whether a command named `west` is even found, or how the 
"other" `west` command compares to the one in your virtual environment.





---
[Visit 
Topic](https://discuss.python.org/t/venv-activate-script-changes-path-while-executing-the-binary-doesnt/67580/2)
 or reply to this email to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click 
here](https://discuss.python.org/email/unsubscribe/d20384154a69698ce82133d879096a35e6112fbaec438235ff1a3b116a6cde75).