Normally when I wish to execute a python file I would change my directory in powershell and use the command,
python -i filename.py
I am currently using the library matplotlib for several scripts. Ive successfully launched them within Pycharm, however i also want to be able to run them within powershell or another console, unfortunately it is having troubles importing. Is there anything i can do?
Related
I have different conda enviroments for different programs that need to be running at the same time (as part of a complex system). So everytime I'm working on this project I have to manually open about six anaconda terminals and copy/paste the commands in each terminal.
I'm looking for a solution where I can write code to open the terminal and execute the instructions. This way I can run this single code to have all of them running.
I saw some people using python to run shell commands but not for Anaconda Prompt.
If you have any idea of what I can use for that, it would be great.
I am a beginner in python and seeking some help on this matter. I want to convert my python script into .exe file which can further be used by the user that don't have python installed. I used to be able to create .exe files using pyinstaller and they worked perfectly. I had used the libraries like pandas, numpy, datetime, pyodbc.
Now, I created a new script that ran perfectly using jupyter notebook and I converted it into exe file, but when I run the file, it opens the command prompt and stays open forever but does nothing. I had two new libraries that I used this time 'xlwings', 'shutil'. I thought that might be the problem so I ran the same script removing those two libraries but still can't get it working. I am completely stuck here and couldn't figure what went wrong.
I've added a print('Start') command in the beginning of the script but the exe file doesn't even read that. Seems like it isn't executing the code at all.
I am using python 3.9.5 and PyInstaller version 4.10 and running it on windows 10.
Thanks in advance.
I wrote a script on my Windows machine using python 3.6.0. I wanted to run it on Linux machines as well so I transferred the .py script onto my Ubuntu VM. The problem is, I tried to install python 3.6.0 in every way possible but it doesn't really work. Python3 works when I want to execute a .py file, but since I am trying to use pyisntaller to convert it into an executable for linux, I need the default version as 3.6.0. python --version gives me Python 2.7.2. How can I fix this so when I do python --version it shows 3.6.0?
There is no point in changing your default python version, Ubuntu relies heavily on older versions of python. And what do you mean by convert it into an executable for Linux? Almost every file on your file system is an executable. If you want to make your program run as a command in the terminal you can do this though:
text_editor_of_your_choice .bashrc
This should open the hidden .bashrc file, and scroll to the bottom of it. Below is what the file looks like...
.bashrc
After that you can create a function for the python command you want to run.
eg. function ghst {python3.6 /home/user/example_script/example.py $#}
Start a terminal session and then try running it. Now that's if you want to run it inside the terminal. If it you want to create this "executable file" you speak of you can create a simple shell script.
First go in the terminal and run touch file_name_of_your_choice.sh
This will create a blank file named file_name_of_your_choice with the file extension "sh". After that open the text file in whatever directory you created it in, if you are unsure do pwd.
In your first line make sure that the user is inside the directory of the .py file by doing
cd /home/user/folder/ On the next line you should then execute the .py file. You can do this by typing this: python3 file.py. This will execute the program inside a terminal window. After you have done all of this make sure that the python file and the script file are executable. Do this by doing chmod +x file.py and chmod file.sh.
This is what the end result looks like
example script
You mentioned inside your question that you want your program to be able to run on Linux machines as well. Whether this is for personal or a public project of some sort it comes in handy by packaging all the required files in a .zip format this makes it easy to unpack everything when moving to separate machines. If there are any problems let me know.
I have a python script that processes excel files. I this script is run via python from the command line, it runs as expected but when I run from incron, it does't appear to see my imports, such as pandas
this is how I call from incron:
file/to/monitor IN_CREATE,IN_MOVED_TO /usr/bin/sh /my/main/shell/script
this is how my script looks like
#!/usr/bin/env python
source activate my_env
python /absolute/path/to/python/script
and now as I check on the logs, from abrt,
step1.1_executeConsolidation.py:2::ImportError: No module named pandas
I'm thinking this is just an environment issue with incron, but I'm not sure how to set it up properly.
I use anaconda by the way. If run manually, I don't have any library dependency issues
I am trying to work on a lab machine using Python scripts that run fine on my local machine. The scripts were written for Python 2.7, and use the AARDVARK device library as an imported module.
The script runs on Windows' command shell, but fail to run on the installed Cygwin bash shell. The PYTHONPATH variable is defined correctly and similar to my local machine. When running, it complains that it cannot fin the AARDVARK module. So, following this question, I added the sys.path.append('/cygdrive/c/aardvark') command to my script.
Now, when I try running it, I get a pop-up message window saying Unable to bind Python API. API supports Python 2.3,2.4,2.5,2.6,2.7. Running python --version on the bash command line, I get 2.6.7.
What is this error message and how to eliminate it?
How can I make the script run and use the aardvark module?