Python 2.7: No module named hexchat - python-2.7

I'm trying to write a Python script that does something with the inputs from the IRC chat that is connected to twitch.
However, when I do import hexchat, python keeps telling me there is no module named hexchat. I'm using Pycharm btw. I just want to be able to use the functionality in the hexchat module. Any help would be appreciated!

You need to first download and install Hex Chat module from here Downloads and then do the import hexchat.
For Linux - sudo apt-get install hexchat
Documentation for Python API is here Documentation

You load scripts inside hexchat. Window > Plugins and Scripts > Load.

I was having this issue on Windows 10 but I managed to resolve it by loading .py scripts in Hexchat like the below:
/py load "C:\where\your\file\is.py"
You also want to have module info in your .py file too otherwise Hexchat will complain:
__module_name__ = "helloworld"
__module_version__ = "1.0"
__module_description__ = "Python module example"

Related

ImportError when running a Python script from within a Shell script

I am trying to write a small shell script, which at the end invokes a small Python script. The end of shell script is as follows:
echo $pythonFilePath
cd $pythonFilePath
python Python-webtest.py
I have made the Python-webtest.py as executable. However, when the shell script is executed, I get the following error, coming from the python script
Traceback (most recent call last):
File "Python-webtest.py", line 2, in <module>
from selenium import webdriver
ImportError: No module named selenium
The following is my python script
#!/usr/bin/env python
from selenium import webdriver
webdriver.Firefox()
I have no issues when I try to run the stand alone python script and executes without any issues.
I try on my machine and it's working, the unique difference that you didn't mentioned and maybe is the reason for why it's not working for you is that I introduced selenium in the windows environment variables.
Right click on Computer->properties (or just go to Control
Panel\System and Security\System)
Click the Advanced system settings link.
Click on Advanced
Click Environment Variables.
In the section System Variables,find the PATH environment variable
and select it.
Click Edit. If the PATH environment variable of selenium does not
exist in the list,add it at the end and save.
IMPORTANT: don't delete the existing environment variables
I think I found the problem. I had a python installation from anaconda and while, I had done a pip install it appears to have done within the anaconda installation directory. I completely removed anaconda and then did pip install -U selenium and ran the shell script and without any issues, the python script also did its job.

Odoo custom module with external Python library

I created an Odoo Module in Python using the Python library ujson.
I installed this library on my development server manually with pip install ujson.
Now I want to install the Module on my live server. Can I somehow tell the Odoo Module to install the ujson library when it is installed? So I just have to add the Module to my addons path and install it via the Odoo Web Interface?
Another reason to have this automated would be if I like to share my custom module, so others don't have to install the library manually on their server.
Any suggestions how to configure my Module that way? Or should I just include the library's directory in my module?
You should try-except the import to handle problems on odoo server start:
try:
from external_dependency import ClassA
except ImportError:
pass
And for other users of your module, extend the external_dependencies in your module manifest (v9 and less: __openerp__.py; v10+: __manifest__.py), which will prompt a warning on installation:
"external_dependencies": {
'python': ['external_dependency']
},
Big thanks goes to Ivan and his Blog
Thank you for your help, #Walid Mashal and #CZoellner, you both pointed me to the right direction.
I solved this task now with the following code added to the __init__.py of my module:
import pip
try:
import ujson
except ImportError:
print('\n There was no such module named -ujson- installed')
print('xxxxxxxxxxxxxxxx installing ujson xxxxxxxxxxxxxx')
pip.main(['install', 'ujson'])
In python file using the following command, you can install it (it works for odoo only). Eg: Here I am going to install xlsxwriter
try:
import xlsxwriter
except:
os.system("pip install xlsxwriter")
import xlsxwriter
The following is the code that is used in odoo base module report in base addons inside report.py (odoo_root_folder/addons/report/models/report.py) to install wkhtmltopdf.
from openerp.tools.misc import find_in_path
import subprocess
def _get_wkhtmltopdf_bin():
return find_in_path('wkhtmltopdf')
try:
process = subprocess.Popen([_get_wkhtmltopdf_bin(), '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except (OSError, IOError):
_logger.info('You need Wkhtmltopdf to print a pdf version of the reports.')
basically you need to find some python code that will run the library and install it and include that code in one of you .py files, and that should do it.

No module named webdriver

I've just installed Selenium (I'm that new to it) for Python using
sudo -H pip install selenium
and at the following command
from selenium.webdriver import Firefox
I get
No module named webdriver
Any thoughts?
Most probably your Python file is called
selenium.py
Python interpreter at first tries to import files from directory you're in, so the solution is to rename the executed file and issue will be gone.
Check if site packages link is added in system environment variables;
C:\Python27\Lib\site-packages;
On windows start, type environment variables. Click on the "Edit the system environment variables" . Click -> Environment variables -> Under System Variables-> Scroll down to find "Path" -> Edit and add above path.
first you need to import
from selenium import webdriver
then you can use other imports

Unable to run setup.py behind proxy

I'm new to python (and linux) and I'm trying to run the setup.py, however it's not working properly because there's a corporative proxy blocking te request to pypi.
I check this link to properly use the setup.py and also check this and this solutions in stackoverflow but I can't make them work (or I'm wrong in the way I'm applying them).
I'm using:
virtualenv
virtualenvwrapper
python 2.7
Ubuntu 14
I already add the http_proxy and https_proxy in .profile and .bashrc.
When I use pip install --proxy the.proxy:port some_module it's working properly (also I know the env variables do something is because before that I can't even get to stackoverflow.com, so I'm assuming they work just fine).
What I have already tried is:
Trying to use --proxy on python
Look for something similar to --proxy in python
Trying to add the proxy configuration described in one of the solutions mentioned earlier in my setup.py (which is add to the description of this problem)
Tried and successfully downloaded a couple of modules with pip --proxy (this is my current not-so-good-solution)
Messing with the python configuration files in the virtualenv in hope of find some proxy config
My setup.py file looks like this:
from setuptools import setup, find_packages
import requests
with open('development.txt') as file:
install_requires = file.readlines()
with open('development_test.txt') as file_test:
test_requires = file_test.readlines()
setup(
name="my_project",
version="1.0.0-SNAPSHOT",
packages=find_packages(),
install_requires=install_requires,
test_suite="nose.collector",
tests_require=test_requires,
)
proxies = {
"http": "http://proxy.myproxy.com:3333",
"https": "http://proxy.myproxy.com:3333",
}
# not sure what goes here... tried a few things but nothing happend
requests.get("https://pypi.python.org", proxies=proxies)
I'll try any suggestion, any help appreciated.
Thanks
After a deep search about how python works and not being able to find the problem I start looking to how the bash commands work.
It turn out you have to export the http_proxy variables with sudo -E.
A rocky mistake.

Import error web "no module named web"

I did an web application using web.py and after a while I realize that my python compiler was configure to use python2 instead of python3 (both are installed). With python2 my application was working but I got string in unicode so I try to execute my code using python3:
python3 mycode.py
But I get different kind of error, the lib urlparse was not found (this problem was cause by a new name in python3 which is urllib) but I got a problem with:
import web
The return error is:
ImportError: No module named 'web'
I can't figure out where the problem come from.
Web.py cannot work with python3, this is the linked to the gitub project.
https://github.com/webpy/webpy/issues/108
Maybe you have installed web in your python2 lib but you have none in python3 lib... Check it out