I have already installed the lib with pip install, but I can import that
import openai
openai.api_keys = '*mykey*'
model_engine = 'text-davinci-003'
prompt = 'Hello, how are you today?'
completion = openai.Completion.create(
engine=model_engine,
prompt=prompt,
max_tokens=1024,
n=1,
stop=None,
temperature=0.5,
)
response = completion.choices[0].text
print(response)
I already installed the library with pip3, with pip, I already checked if it's in the right place with pip show (and it's in python 3.6).
Related
I've the below GitHub workflow where I need to run python code to get the token but after the steps are ran I'm getting error "ModuleNotFoundError: No module named 'authlib'" I have installed the required dependency. Works fine when I run locally please can someone help me
- name: Get Token
run: |
python -m pip install --upgrade pip
pip install requests-oauthlib
python -c "from authlib.integrations.requests_client import OAuth2Session;"
if __name__ == '__main__':
from authlib.integrations.requests_client import OAuth2Session
token_endpoint = "https://example.com"
client_id = "********"
client_secret = "******"
session = OAuth2Session(client_id, client_secret)
session.fetch_token(token_endpoint)
access_token = session.token["access_token"]
print(access_token)
Please install Authlib package. https://pypi.org/project/Authlib/
pip install Authlib
I have a setup.py script for my package which I install using
python ./setup.py install
What seems to happen is every time I increase the version, the old version is not removed in /usr/local/lib/python2.7/dist-packages so I see multiple versions.
Is there a way to set this up in a way that when a person updates, the old version gets removed?
There is a similar (but not quite) question on SO that asks how to uninstall a package in setup.py but I'm not really looking to uninstall as a separate option. I am looking for a clean 'update' process that removes old versions before installing new ones.
The other option is if I could just cleanly remove the version number from the installed package name, in which case I suppose it would overwrite, but I haven't been successful in doing that. If I remove version, it creates the package name with "0.0" which looks weird.
My setup script:
import io
import os
import sys
from setuptools import setup
#Package meta-data.
NAME = 'my_package'
DESCRIPTION = 'My description'
URL = 'https://github.com/myurl'
EMAIL = 'myemail#gmail.com'
AUTHOR = 'Me'
VERSION = '3.1.12'
setup(name = NAME,
version=VERSION,
py_modules = ['dir.mod1',
'dir.mod2',
]
)
If you want to remove previous versions from your packages then you could use pip in the parent directory of your package. Lets assume your setup.py is in the directory my_package then you can use:
pip install my_package --upgrade
I've created a python package that is posted to pypi.org. The package consists of a single .py file, which is the same name as the package.
After installing the package via pip (pip install package_name) in a conda or standard python environment I must use the following statement to import a function from this module:
from package_name.package_name import function_x
How can I reorganise my package or adjust my installation command so that I may use import statement
from package_name import function_x
which I have successfully used when I install via python setup.py install.
My setup.py is below
setup(
name = "package_name",
version = "...",
packages=find_packages(exclude=['examples', 'docs', 'build', 'dist']),
)
Change your setup arguments from using packages to using py_modules e.g.
setup(
name = "package_name",
version = "..",
py_modules=['package_name'],
)
This is documented here https://docs.python.org/2/distutils/introduction.html#a-simple-example
I was able to get geolite2 working on python2.7 - but i needed 3.4. I found the instructions for 2.7 on this link: http://pythonhosted.org/python-geoip/. Code fragments are also provided.
pip install python-geoip
pip install python-geoip-geolite2
>>> from geoip import geolite2
>>> match = geolite2.lookup('17.0.0.1')
>>> match is not None
True
So I naturally changed all the pip to pip3 and installed on a fresh VM. There is no error on the code but it does not looup and return values from their db.
pip3 install python-geoip
pip3 install python-geoip-geolite2
In the 2.7 VM, when I used 3.4, I pointed the geoip lib at /usr/local/lib/python2.7/dist-packages - no luck either. It however works on 2.7 on the same VM.
What should I need to do to make it to work on 3.4?
python-geoip does not support Python 3 and has not been updated in two years. Although there is a pull request to add Python 3 support, I would not expect it to be merged and released any time soon. I would recommend using the official MaxMind geoip2 package instead.
Install:
apt install python3-pip
pip3 install maxminddb
pip3 install maxminddb-geolite2
Example use:
#!/usr/bin/python3
# coding=utf-8
from geolite2 import geolite2
reader = geolite2.reader()
# google's ip
match = reader.get('172.217.16.163')
if match:
# print(match)
if 'country' in match:
print(match['country']['iso_code'])
else:
print(match['continent']['code'])
else:
print('')
python-geoip with python 3 support (install with pip or pip3):
pip3 install python-geoip-python3
output:
Collecting python-geoip-python3
Downloading python_geoip_python3-1.3-py2.py3-none-any.whl (7.4 kB)
Installing collected packages: python-geoip-python3
Successfully installed python-geoip-python3-1.3
for geolite2:
pip3 install python-geoip-geolite2
output:
Successfully built python-geoip-geolite2
Installing collected packages: python-geoip-geolite2
Successfully installed python-geoip-geolite2-2015.303
example with test_geoip.py:
#!/usr/bin/env python3
import socket
from geoip import geolite2
import argparse
import json
# Setup commandline arguments
parser = argparse.ArgumentParser(description='Get IP Geolocation info')
parser.add_argument('--hostname', action="store", dest="hostname", required=True)
# Parse arguments
given_args = parser.parse_args()
hostname = given_args.hostname
ip_address = socket.gethostbyname(hostname)
print("IP address: {0}".format(ip_address))
match = geolite2.lookup(ip_address)
if match is not None:
print('Country: ',match.country)
print('Continent: ',match.continent)
print('Time zone: ', match.timezone)
print('Location: ', match.location)
run:
python3 test_geoip.py --hostname=amazon.co.uk
output:
IP address: 178.236.7.220
Country: IE
Continent: EU
Time zone: Europe/Dublin
Location: (53.3478, -6.2597)
run again:
python3 test_geoip.py --hostname=amazon.co.uk
output:
IP address: 54.239.34.171
Country: US
Continent: NA
Time zone: America/Los_Angeles
Location: (47.6103, -122.3341)
To use the maxmind db:
Install:
maxminddb
maxminddb-geolite
In your code:
from geolite2 import geolite2
match = geolite2.reader()
geoip = match.get('xxx.xxx.xxx.xxx')
The Ipython documentation mentions that there are different commands to install Ipython with pip, for example:
pip install "ipython[all]"
pip install "ipython[terminal]"
pip install "ipython[parallel]"
pip install "ipython[notebook]"
How does it work? How can I use such "options" for another package.
You can check setup.py in ipython-3.0.0.
extras_require = dict(
parallel = [pyzmq],
qtconsole = [pyzmq, 'pygments'],
doc = ['Sphinx>=1.1', 'numpydoc'],
test = ['nose>=0.10.1', 'requests'],
terminal = [],
nbformat = ['jsonschema>=2.0'],
notebook = ['tornado>=4.0', pyzmq, 'jinja2', 'pygments', 'mistune>=0.5'],
nbconvert = ['pygments', 'jinja2', 'mistune>=0.3.1']
)
For instance, if you enter pip install "ipython[parallel]", pip will go to PyPi to find this package and download it.
So if you want to apply command like this to other packages, you have to make sure there is something like this in its setup.py.