Running Python script from Ubuntu terminal NameError - python

I have recently moved from Python on Windows to Python on Ubuntu. In Windows I could just hit F5 in the IDLE editor to run the script. However, in Ubuntu I have to run the script by typing python /path/to/file.py to execute.
The thing is it seems the imports within the file are not working when I run from command line.
It gives me the error:
NameError: global name 'open_file' is not defined
This is the open_file method of Pytables. In the python file I have:
from tables import *
I have made the file executable and all.
Appreciate your help.

The pytables on my ubuntu system is 2.3.1. I think that open_file is a version 3 thing. I'm not sure where you can pick up the latest package, but you could always install the latest with pip.

Related

How to run a python library without installing it

I have to run a shell script on a Centos Linux machine that calls a python file. Inside the python file, there is the following code snippet:
from lib.rclone import Rclone
rclone = Rclone()
if shutil.which("rclone") == None:
print("Rclone executable is missing, install it")`
The problem is that I am not supposed to install any code (including rclone) on the machine. Therefore, whenever I call the shell script, it ends up with the error message. I don't know how can I successfully run it?
The program you are running requires rclone. Since you cannot install it, you cannot run it. Simple as that.
You can try to release the script as a .exe file.
By using pyinstaller (https://pyinstaller.org/) you don't have to install any libs or py package on the target machine, you can even choose to release it as a single executable.

Python3 installed, but why can't I run python file in terminal

I am trying to run a python3 file out of the directory the file is located in on macOS catalina.
so I type the following:
python3 <file_name>
and nothing happens in my terminal, it just starts a new line in the same directory, but no file runs.
Up until now I have only ever used a jupyter notebook to run python, but now I am trying to run VS code and run the file inside of the terminal.
Anyone know how to fix?
I just wanted to say I fixed the problem trying a number of different solutions:
I downloaded the most recent version of python, ran certificates and update commands.
I selected the new python interpreter from VS code using shift+cmd+P and select interpreter option.
I ran the file in python launcher and then again in terminal and it works fine now. Thanks for participating in helping me solve this issue.
Alternatively if anyone else has similar problems, try the steps I mentioned, or maybe try setting up a pyenv to run python files in a virtual python environment.

Python ran from command line runs version 3.6 while in my files it runs version 3.4

So I have 2 versions of python on my machine, one located at: # python 3.4
c:/Python34
other located at: # python 3.6
c:\users\USERNAME\appdata\local\programs\python\python36-32
The python 3.6 version has all the libraries I would like to use, however when I try to run my python scripts I get errors saying the module doesn't exist.
Now if i run python though the command line like this it works fine.
So I would like to force my scripts to run though the version where I have all the libraries downloaded.
In my path I have.
C:\Users\USERNAME\AppData\Local\Programs\Python\Python36-32\Scripts;
C:\Users\USERNAME\AppData\Local\Programs\Python\Python36-32\;
C:\Users\USERNAME\AppData\Local\Programs\Python\Launcher;
So when I run my program in the command line I would like it to run using the correct version of python I don't know why its using the other one and it's driving me nutz!
I've uninstalled and reinstalled pandas and numpy with pip install and pip uninstall
I've switched the environment variables to point to Python34 in my command line and attempted to install pandas on that but it was too painful.
I'm writing the code in Sublime Text and running it though the command line just by typing
examplecode.py
When i run
assoc.py
and
ftype Python.file
i get theses messages
This was fixed simply by creating a virtual environment with the libraries i needed.
Thanks to ascripter for the advice.
I would have rather just deleted the python 3.4 however this isnt my machine so i don't want to make any waves. good suggestion abarnert!

Python: ModuleNotFound error when starting script manually

When I double-click the script to run it raises ModuleNotFound error. However, when I execute python main.py, the script works just fine. What can be causing it? I have a fresh 3.6.1 installation.
The telebot module is successfully installed and working.
Here's to clarify:
When I double-click or run main.py from console, the script throws an error because it cannot find a module. (probably because it runs from a distant folder)
When I run python main.py from the same folder the script works well. All modules are recognized and loaded. (my guess is that python command runs python.exe which is located where all of the modules are)
My Path environment variable is pointing to the correct folder.
I only have one python installation and one version.
It seems that you have installed both 32 bit and 64bit Pythons but have installed a package in only one of them. You can one of the following:
uninstall the one that doesn't have the package installed and add the remaining one to the path variable, or
you can install package in both 32bit and 64bit python.

IDLE3 installed for Python however I can't open it

My linux distribution(Opensuse 42.2) comes with python 2.7 already installed, however I installed python3 on top of that. And in order to launch IDLE to run the python3 shell, I was told to install "python3-tools" and then just run "idle3" in terminal to launch the shell. However running "idle3" in terminal only brings up an error message, and I can't find any other suggestions. Any help would be extremely appreciated.
** I have fixed the problem. The sources that I found gave me the improper package name. After searching the main-repository for Opensuse, the proper package name for python3 IDLE was "python3-idle".

Categories