Twittersearch module is not getting imported to api file - python

I am trying to make twitter search api everything was working fine but suddenly twittersearch() module is not getting imported. I am using python 3.4.2 with windows 8.1 64-bit. I have tried easy_install twittersearch it successfully installs packages and everything is fine but when I run this code
from TwitterSearch import *
import pyodbc
cnxn = pyodbc.connect(driver='{SQL Server}', server='localhost', database='capstone',trusted_connection='yes')
cursor = cnxn.cursor()
cursor.execute("select word from dbo.search where sl in (select max(sl) from dbo.search)")
for row in cursor.fetchall():
print (row)
print("This is positive data ")
term = row[0]
try:
tso=TwitterSearchOrder()
tso.set_keywords([term])
tso.set_language('en')
When i execute this it shows errors like below
Traceback (most recent call last):
File "C:\Python34\search_test.py", line 18, in <module>
tso=TwitterSearchOrder()
NameError: name 'TwitterSearchOrder' is not defined
But it is actually there I don't know why it is not recognizing the module. till 2 days back it was running successfully with IDLE but not in commandprompt and I have reinstalled the python and added all tools, now it is showing this error in both IDLE and command prompt
TIA

Make sure that TwitterSearch is in your lib\site-packages path. If it is you must've installed it right. If not, a simple python -m pip install TwitterSearch from command prompt will do.
However, there seems to be an issue(bug) with TwitterSearch wrt its functions. You might consider using an alternate API in the meantime. I would suggest using Tweepy

Related

While trying to run cryptocode I get the error: "module 'hashlib' has no attribute 'scrypt'"

As I mentioned in the title Im trying to run the library cryptocode by using this simple code:
import cryptocode
password = "This is a test"
key = "My Key"
def encrypt(password, key):
return cryptocode.encrypt(password, key)
def decrypt(encryptetpass):
return cryptocode.decrypt(encryptetpass, key)
encrypted_pass = encrypt(password, key)
print(encrypted_pass)
print(decrypt(encrypted_pass))
While running it locally on Windows I get no errors, but trying the same on Linux generates me the previously in the title mentioned error:
(venv) pwd$ python3.9 crypt_test.py
Traceback (most recent call last):
File "/crypt_test.py", line 15, in <module>
encrypted_pass = encrypt(password, key)
File "/crypt_test.py", line 8, in encrypt
return cryptocode.encrypt(password, key)
File "/venv/lib/python3.9/site-packages/cryptocode/myfunctions.py", line 16, in encrypt
private_key = hashlib.scrypt(
AttributeError: module 'hashlib' has no attribute 'scrypt'
I tried updating Openssl, reinstalled my venv and Python.
check below points:
To check which all versions are installed
which python
//use python or python3 as per your needs
To check where all versions are installed
where python
//use python or python3 as per your needs
In mycase i was having two paths as below,
/usr/bin/python
/usr/local/bin/python
so, now check VS Code,
Command + Shipt + P
Search/Select Python Interpreter
select appropriate version you are using, if not listed Add the respective path and select the same.
This Solution worked for me:)
Did you try to build the latest OpenSSL? I see instructions here: https://www.howtoforge.com/tutorial/how-to-install-openssl-from-source-on-linux/
(wasn't able to try this because I'm not running Linux). Please let us know if this worked.

Problem Creating One File exe with pyinstaller and pysqlcipher

I'm trying to create a one file .exe to run on any windows machine but I've hit a problem with pysqlcipher. I've gone back to some basic code that just creates a simple database with a key, on my dev machine all works fine whether I use the python file or the compiled exe. I seem to be missing a library, path or both? I've tried adding vaious items using --add-data but have spent hours and made no progress. Here is the basic bit of python:-
from pysqlcipher3 import dbapi2 as sqlite
import os
import sys
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
try:
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
conn = sqlite.connect('test.db')
c = conn.cursor()
c.execute("PRAGMA key='password'")
c.execute('''create table stocks (date text, trans text, symbol text, qty real, price real)''')
c.execute("""insert into stocks values ('2006-01-05','BUY','RHAT',100,35.14)""")
conn.commit()
c.close()
When I run the exe on a different windows 10 PC I get this error
Traceback (most recent call last):
File "testdb.py", line 1, in
File "c:\users\xxx\appdata\local\programs\python\python38\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
File "site-packages\pysqlcipher3-1.0.3-py3.8-win-amd64.egg\pysqlcipher3\dbapi2.py", line 33, in
ModuleNotFoundError: No module named 'pysqlcipher3._sqlite3'
[9248] Failed to execute script testdb
The error references the path on my dev PC and also refers to line 33 in dbapi2.py which is:-
from pysqlcipher3._sqlite3 import *
I have tried adding various files when running pyinstaller but I am making no progress, I'm sure its nothing simple but need help please.
I encountered a similar problem a while back and one thing that worked for me is adding the sqlite3 dll in the spec file of pyinstaller. It is also possible to add it from command line. I had tried many other things before such as re-creating a conda environment and rebuilding my python package but that did not work. In your spec file where you add the pyinstaller binaries please try something like.
binaries=[('C:\\Users\\myname\\newfolder\\sqlite3.dll','.')]
You can download the DLL from https://www.sqlite.org/download.html depending on windows or linux platform . Once you add the dll and recompile it should be fine. I think this error is primarily happening as dbapi2 requests the sqlite3 dll which in my case atlease was missing from the DLL folder. I just downloaded and added it in my spec file, but you can also try to add it to the hookspath or ENV folder.

Change where pyodbc expects libodbc.2.dylib to live (changing default odbc file locations)

When importing pyodbc
❯ python
>>> import pyodbc
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(/Users/pcosta/Documents/test/myenv/lib/python3.7/site-packages/pyodbc.cpython-37m-darwin.so, 2): Library not loaded: /usr/local/opt/unixodbc/lib/libodbc.2.dylib
Referenced from: /Users/pcosta/Documents/test/myenv/lib/python3.7/site-packages/pyodbc.cpython-37m-darwin.so
Reason: image not found
I know why this is happening, as I don't have libodbc.2.dylib in the expected location. The reason is I do not have permission to write to /usr/local/, so I have Homebrew installing into ~/.brew. This mostly works fine. I am even able to get both tsql and isql working as expected by following the steps outlined here: https://github.com/mkleehammer/pyodbc/wiki/Connecting-to-SQL-Server-from-Mac-OSX.
So I do have libodbc.2.dylib, it's just that it lives in /Users/pcosta/.brew/lib, not /usr/local/opt/unixodbc/lib.
The main questions is can I get pyodbc to look for libodbc.2.dylib (and other associated files) in another directory?
I have all the files needed and have configured them correctly, I just need to repoint pyodbc somehow.
Thanks!
Thanks in part to guidance from this GitHub issue I was able to come to some solution.
Assuming you have brew install unixodbc:
Add the following paths (to .zshrc, .bashrc, or .bash_profile):
export LDFLAGS="-L/Users/pcosta/homebrew/opt/unixodbc/lib $LDFLAGS"
export CPPFLAGS="-I/Users/pcosta/homebrew/opt/unixodbc/include $CPPFLAGS"
export PKG_CONFIG_PATH="/Users/pcosta/homebrew/opt/unixodbc/lib/pkgconfig $PKG_CONFIG_PATH"
Run pip install --no-binary pyodbc pyodbc to bypass the binary and build yourself

OpenERP & Python Tools for Visual Studio compile error

I'm trying to get the OpenERP server to build and run in Visual Studio 2012 using Python Tools for Visual Studio.
At the moment I get more than 2300 error messages, mostly along the lines of:
unexpected token 'x1'
I've downloaded the openerp-server-6.0.4 source and created a new Python project from Existing Python Code project in VS. I've selected the path to the OpenERP source(C:\OpenERP\Bin) when prompted and the file to execute when F5 is pressed is openerp-server.py. I've selected the Python 64-bit 3.3 interpreter.
The project is created, but even before building I receive the numerous unexpected token errors. For example in the account.py file it complain about an unexpected token 'tax' in the following code:
tax.type=='code':
address = address_id and obj_partener_address.browse(cr, uid, address_id) or None
localdict = {'price_unit':cur_price_unit, 'address':address, 'product':product, 'partner':partner}
exec tax.python_compute in localdict
amount = localdict['result']
data['amount'] = amount
When using TOOLS > Python Tools > Execute Project in Python Interactive I see the following result:
Python interactive window. Type $help for a list of commands.
Resetting execution engine
Interactive window is not yet started.
Running C:\temp\openerp-server-6.0.4\bin\openerp-server.py
Traceback (most recent call last):
File "C:\temp\openerp-server-6.0.4\bin\openerp-server.py", line 64, in
import tools
File "C:\temp\openerp-server-6.0.4\bin\tools__init__.py", line 23, in
import win32
ImportError: No module named 'win32'
Can anyone guide me into getting OpenERP to build and run using VS? Is it even possible?
Thank you!
You have to install
http://www.py2exe.org/index.cgi/PyOpenGL
Please try after install this module.

Import error in twilio

I am having the same problem as this thread regarding twilio-python:
twilio.rest missing from twilio python module version 2.0.8?
However I have the same problem but I have 3.3.3 installed. I still get "No module named rest" when trying to import twilio.rest.
Loading the library from stand alone python script works. So I know that pip installing the package worked.
from twilio.rest import TwilioRestClient
def main():
account = "xxxxxxxxxxxxxxxx"
token = "xxxxxxxxxxxxxxxx"
client = TwilioRestClient(account, token)
call = client.calls.create(to="+12223344",
from_="+12223344",
url="http://ironblanket.herokuapp.com/",
method="GET")
if __name__ == "__main__":
main()
but this does not work:
from twilio.rest import TwilioRestClient
def home(request):
client = TwilioRestClient(account, token)
Do you have any idea what I can try next?
I named a python file in my project twilio.py. Since that file was loaded first, then subsequent calls to load twilio would reference that file instead of the twilio library.
TLDR: just don't name your python file twilio.py
Check which versions of pip and python you are running with this command:
which -a python
which -a pip
pip needs to install to a path that your Python executable can read from. Sometimes there will be more than one version of pip like pip-2.5, pip-2.7 etc. You can find all of them by running compgen -c | grep pip. There can also be more than one version of Python, especially if you have Macports or brew or multiple versions of Python installed.
Check which version of the twilio module is installed by running this command:
$ pip freeze | grep twilio # Or pip-2.7 freeze etc.
The output should be twilio==3.3.3.
I hope that helps - please leave a comment if you have more questions.
This Worked For me : (Windows)
Python librarys are in G:\Python\Lib
(Python is installed at G:, it might be different for you)
Download Twilio from github at paste the library at >> G:\Python\Lib <<
import problem gone :)
I had the same issue and it drove me crazy. Finally I figured it out. When you get the error:
AttributeError: module 'twilio' has no attribute 'version'
Look 2 lines above and the error is telling you where it expects to find the twilio file. So I moved it from where it was to where it was asking it to be.
Installed to:
c:\users\rhuds\appdata\local\programs\python\python37-32\lib\site-packages
Moved it to:
Traceback (most recent call last):
File "", line 1, in
import twilio
File "C:\Users\rhuds\AppData\Local\Programs\Python\Python37-32\twilio.py", line 2, in
Now I can import twilio. Besides that, the only other thing I did was uninstall old versions of Python, but I don't think that really mattered.

Categories