Python Forum
Instigating python script from via - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Instigating python script from via (/thread-38098.html)



Instigating python script from via - reddwarfcrew - Sep-02-2022

Hi, I created a py script and have been able to execute it from VBA. However, if I update the py script to require any 'import' line (eg import pandas) then the script won't run. The cmd window flashes up and having video'd it there isn't any error.

So I added some 'input(press enter)' lines into the py script to help debug and it just quits the code every time it gets to an import line. the script runs fine directly in Jupiter etc so the code itself is good and works.

Any ideas?


RE: Instigating python script from via - deanhystad - Sep-02-2022

Does the python you are calling from VBA have pandas installed?


RE: Instigating python script from via - reddwarfcrew - Sep-02-2022

(Sep-02-2022, 08:34 PM)deanhystad Wrote: Does the python you are calling from VBA have pandas installed?

I only have one python installed (to my knowledge). Just been playing more directly in a cmd prompt. I've found out that in cmd prompt I need to 'activate base' first, then the cmd prompt is prefixed with (base), then the script runs. So tried taking my cmd prompt script and creating a bat file and running that, but when I do the script runs until the 'activate base' line.

How can I tell if I have more than one python?

Checking my python version in cmd prompt it states:

Quote:WARNING: This python interpreter is in a condo environment, but the environment has not been activated

Explains why I need the 'activate base' in the cmd window. So how do I keep the environment activated so I dont need this?


RE: Instigating python script from via - snippsat - Sep-02-2022

(Sep-02-2022, 08:46 PM)reddwarfcrew Wrote: I've found out that in cmd prompt I need to 'activate base' first, then the cmd prompt is prefixed with (base), then the script runs.
Then you use Anaconda or Miniconda.
(Sep-02-2022, 08:46 PM)reddwarfcrew Wrote: Checking my python version in cmd prompt it states:

Quote:WARNING: This python interpreter is in a condo environment, but the environment has not been activated
Explains why I need the 'activate base' in the cmd window. So how do I keep the environment activated so I dont need this?
Yes you most always activate environment when in cmd or use Anaconda Prompt which activate base environment automatic.
There also a Navigator,i never use it always command line and not crappy cmd馃敤 but cmder.

You should try to learn about Anaconda as that what you use.
It's come with both conda and pip for installing stuff.

Can also make new environments example in my post here,
then it's like new Python version with pandas matplotlib requests spyder and,
Python version of choice eg now can use python=3.10.5 this has no connection with base or other Python that's installed.


RE: Instigating python script from via - reddwarfcrew - Sep-03-2022

So can I use via to execute the py script via the conda prompt (ie with base activated)?


RE: Instigating python script from via - snippsat - Sep-03-2022

(Sep-03-2022, 08:28 AM)reddwarfcrew Wrote: So can I use via to execute the py script via the conda prompt (ie with base activated)?
Yes when base is active it will use the Anaconda python version no matter what folder you are in.
Can give some tips as i have lot installed and Python versions never interfere if understand how this works.
C:\code
位 python -V
Python 3.10.5

# What python interpreter is used now 
C:\code
位 python -c "import sys; print(sys.executable)"
C:\python310\python.exe

# Test pip(used to install stuff to Python)
C:\code
位 pip -V
pip 22.2.2 from C:\python310\lib\site-packages\pip (python 3.10)
So over is a Python version from python.org
Now will use a Miniconda(same as Anaconda without all 720 packages pre-installed) and activate a environment my own,but works the same as base.
# Activate my environment 
C:\code
位 G:\miniconda3\Scripts\activate.bat tom_env

(tom_env) C:\code
位 python -V
Python 3.10.1

# Point to miniconda 
(tom_env) C:\code
位 python -c "import sys; print(sys.executable)"
G:\miniconda3\envs\tom_env\python.exe

# Point to miniconda 
(tom_env) C:\code
位 pip -V
pip 21.3.1 from G:\miniconda3\envs\tom_env\lib\site-packages\pip (python 3.10)

# Anaconda own installer conda
(tom_env) C:\code
位 conda -V
conda 4.11.0
See that now use a other Python version from Miniconda.
Lest say a have hello.py in folder G:\div_code,can now navigate and run the .py file,as long as (tom_env) or eg (base) is activate it will always use the Miniconda Python version.
(tom_env) C:\code
位 G:

(tom_env) G:\
位 cd div_code

# Run code
(tom_env) G:\div_code
位 python hello.py
hello world

# What python interpreter it used to run code over
(tom_env) G:\div_code
位 python -c "import sys; print(sys.executable)"
G:\miniconda3\envs\tom_env\python.exe
Deactivate it will my other Python version .
(tom_env) G:\div_code
位 conda deactivate

G:\div_code
位 python hello.py
hello world

G:\div_code
位 python -c "import sys; print(sys.executable)"
C:\python310\python.exe



RE: Instigating python script from via - reddwarfcrew - Sep-03-2022

Brilliant, thank you very much.