Python: ModuleNotFound error when starting script manually - python

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.

Related

Python script throws module not found error in pm2 but works in cmd

I want to demonise a python script with pm2 that worked before.
I've created a venv with Python 3.6.8. I installed all modules that are required and tryed the script via console, which works.
But if I start the module via pm2, I get an ModuleNotFound Error:
For all the other 23 scripts it worked as well with pm2.
The venv Python version is 3.6.8, the same as the version from the other venv where it was running before.
Has someone encountered similar behaviour and can give me some suggestions on what I could try to solve the issue?
Reinstalling the module doesn't help.
You should specified the absolute path of your virtual environment
pm2 start 18 --interpreter /path/to/your/.venv/bin/python3
Also remember to check whether is the package exists:
/path/to/your/.venv/bin/python3 -m pip list

ModuleNotFoundError: No Module named selenium whereas it is installed in my virt env

I use PyCharm Edu 2018.3, with a virtual environment path set outside my python application root folder (I use this environment for other python code).
When i run the program from PyCharm, it works without errors. But when i run it from a .bat file it fail to be able to import the packages from my environment.
Basically, it seems like all installed packages made in the environment, are not being found when launched from the .bat file.
So i was wondering if the fact that my environment was outside my root python code was an issue or if i had to precise a path, or else.
All packages imported are correctly inatlled in my envirnment and the code runs as expected when run in PyCharm.
Also, i tried to run a simple "Hello World' code from my .bat file and it works correctly, so issue only occurs when calling packages from my environment.
Could it be a setup file issue (i have none)?
Thank for the help and suggestions.
For instance, the import of selenium which is my first import, in the code, triggers the following error:
#
from selenium.webdriver.firefox.webelement import FirefoxWebElement as MyWeb
Element
ModuleNotFoundError: No module named 'selenium'
#
I'm guessing you have either installed selenium to the virtualenv that PyCharm setup for you when executing from withing the IDE. However When your running outside of the IDE you are using the default python interpreter not your virtualenv. To ensure your in the expected virtualenv make sure it's activated before running.
So for example
$ cd C:\Users\'Username'\venv\Scripts\
$ activate.bat
From this point you should be able to execute your bat script using that virtualenv.
If your still getting it with the virtualenv activated then try installing with pip while your virtualenv is activated.

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!

Error in Trying to Use Python Module

I'm trying to use this module in a project, but can't figure out how to use it.
What I've tried:
Downloaded the module as a ZIP file.
Unzipped that file, giving me the directory structure I saw in the GitHub page.
Opened up Terminal, and navigated to the directory with setup.py in it.
Ran the command sudo python setup.py install
This seemed to run fine, as I get a message saying "Finished processing dependencies"
Now, when I go into PyCharm (the IDE I'm using) and try to run import readability I get an error saying ImportError: No module named 'readability'
Possible reason for failure:
I specified to PyCharm that I am using a Python 3 interpreter. Would Terminal by default install in the 2.x Python directory?
Does the location of my PyCharm .py file matter?
My main error was running the python commands in Terminal under version 2.7.2. By using the keyword python3 instead of python, I was able to force Terminal to use the correct version. I also needed to install setuptools.

Running Python script from Ubuntu terminal NameError

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.

Categories