Python Forum
Instigating python script from via
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Instigating python script from via
#1
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?
Reply
#2
Does the python you are calling from VBA have pandas installed?
Reply
#3
(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?
Reply
#4
(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.
Reply
#5
So can I use via to execute the py script via the conda prompt (ie with base activated)?
Reply
#6
(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
Reply
#7
Brilliant, thank you very much.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 3,328 Jun-29-2023, 11:57 AM
Last Post: gologica
  How to kill a bash script running as root from a python script? jc_lafleur 4 5,954 Jun-26-2020, 10:50 PM
Last Post: jc_lafleur
  crontab on RHEL7 not calling python script wrapped in shell script benthomson 1 2,322 May-28-2020, 05:27 PM
Last Post: micseydel
  Package python script which has different libraries as a single executable or script tej7gandhi 1 2,643 May-11-2019, 08:12 PM
Last Post: keames
  How to run python script which has dependent python script in another folder? PrateekG 1 3,166 May-23-2018, 04:50 PM
Last Post: snippsat
  How to call one python script and use its output in another python script lravikumarvsp 3 32,448 May-16-2018, 02:08 AM
Last Post: lravikumarvsp
  Check Python version from inside script? Run Pythons script in v2 compatibility mode? pstein 2 9,861 Jul-07-2017, 08:59 AM
Last Post: snippsat
  Cant pass corect variables to python script in bash script neradp 3 6,226 Nov-05-2016, 01:26 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020