In my python project, I have this hierarchy
+ slack_app
+ src
+ apps
+ intro
+ \__main__.py
+ slack_app.py
+ setup.py
This is my setup.py:
setup(
name= "my-slack-app",
packages = find_packages(),
entry_points = {
'console_scripts': [
'slack-app = src.apps.intro.__main__:main',
],
})
__main__.py:
def main():
print("WORKED")
if __name__ == "__main__":
main()
I run python3 setup.py install, then run my app which is installed in /usr/local/python3.6/bin but I always get this error when I run it:
Traceback (most recent call last):
File "/usr/local/python3.6/bin/slack-app", line 11, in <module>
load_entry_point('my-slack-app==0.1.dev2+g4fd21b0.d20200309',
'console_scripts', 'slack-app')()
File "/usr/local/python3.6/lib/python3.6/site-
packages/pkg_resources/__init__.py", line 490, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/local/python3.6/lib/python3.6/site-
packages/pkg_resources/__init__.py", line 2854, in
load_entry_point
return ep.load()
File "/usr/local/python3.6/lib/python3.6/site-
packages/pkg_resources/__init__.py", line 2445, in load
return self.resolve()
File "/usr/local/python3.6/lib/python3.6/site-
packages/pkg_resources/__init__.py", line 2451, in resolve
module = __import__(self.module_name, fromlist=['__name__'],
level=0)
ModuleNotFoundError: No module named 'src.apps'
Any help please?
If you are using setuptools.find_packages, then you need to have __init__.py files. Also you are using the so-called src-layout so you need to adjust the package_dir and set the where parameter of find_packages.
Reference:
https://setuptools.readthedocs.io/en/latest/setuptools.html#using-find-packages
Related
my python code I'm trying to run:
import curses, random
def main(stdscr):
stdscr.clear()
for i in range(0, 21):
stdscr.addstr(i, 0, f'count {i+1}, and rand value {random.randint(0, 100)}')
stdscr.refresh()
stdscr.getkey()
curses.wrapper(main)
print("ngos")
then I use this for py2exe:
from distutils.core import setup
import py2exe
setup(windows=[{"script":"main.py"}], options = {"py2exe":{"packages": ["curses",]}})
but when I try and run the exe I get this from the log:
Traceback (most recent call last):
File "main.py", line 1, in <module>
File "<frozen zipimport>", line 259, in load_module
File "curses\__init__.pyc", line 13, in <module>
ModuleNotFoundError: No module named '_curses'
I'm using win10 x64
I'm attempting to run a SPARQL query using the Python package wikibaseintegrator (version 0.10.0).
The program is written as follows:
from wikibaseintegrator.wbi_config import config as wbi_config
from wikibaseintegrator import wbi_login, wbi_core
wbi_config['MEDIAWIKI_API_URL'] = 'http://localhost/database_name/api.php'
wbi_config['SPARQL_ENDPOINT_URL'] = 'http://localhost:8989/database_name/sparql'
wbi_config['WIKIBASE_URL'] = 'http://wikibase.svc'
temp_username = "placeholder_username"
temp_password = "placeholder_password"
def main():
login_instance = login()
sparql_str = """
SELECT ?item ?itemLabel
WHERE
{
?item wdt:P98 wd:Q45.
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
"""
sparql_results = run_sparql_query(sparql_str)
print(sparql_results)
def login(username=temp_username, password=temp_password):
login_instance = wbi_login.Login(user=username, pwd=password)
return login_instance
def run_sparql_query(sparql_str):
sparql_results = wbi_core.ItemsEngine.execute_sparql_query(sparql_str, endpoint=wbi_config['SPARQL_ENDPOINT_URL'])
return sparql_results
# MAIN
if __name__ == "__main__": main()
When I run this though, the error I get is:
Traceback (most recent call last):
File "database_script.py", line 52, in <module>
if __name__ == "__main__": main()
File "database_script.py", line 40, in main
sparql_results = run_sparql_query(sparql_str)
File "database_script.py", line 48, in run_sparql_query
sparql_results = wbi_core.ItemsEngine.execute_sparql_query(sparql_str, endpoint=wbi_config['SPARQL_ENDPOINT_URL'])
AttributeError: module 'wikibaseintegrator.wbi_core' has no attribute 'ItemsEngine'
However, the documentation (https://github.com/LeMyst/WikibaseIntegrator) seems to imply that this is the correct way to format the query. Any help in diagnosing would be much appreciated!
EDIT 1: The documentation says it's in the ItemEngine (The method wbi_core.ItemEngine.execute_sparql_query()), but the program itself seems to show it being in the FuctionsEngine
I have tried all of these variations, with the error being the same:
$ python database_script.py
Traceback (most recent call last):
File "database_script.py", line 52, in <module>
if __name__ == "__main__": main()
File "database_script.py", line 40, in main
sparql_results = run_sparql_query(sparql_str)
File "database_script.py", line 48, in run_sparql_query
sparql_results = wbi_core.FuctionsEngine.execute_sparql_query(sparql_str, endpoint=wbi_config['SPARQL_ENDPOINT_URL'])
AttributeError: module 'wikibaseintegrator.wbi_core' has no attribute 'FuctionsEngine'
$ python database_script.py
Traceback (most recent call last):
File "database_script.py", line 52, in <module>
if __name__ == "__main__": main()
File "database_script.py", line 40, in main
sparql_results = run_sparql_query(sparql_str)
File "database_script.py", line 48, in run_sparql_query
sparql_results = wbi_core.ItemEngine.execute_sparql_query(sparql_str, endpoint=wbi_config['SPARQL_ENDPOINT_URL'])
AttributeError: type object 'ItemEngine' has no attribute 'execute_sparql_query'
$ python database_script.py
Traceback (most recent call last):
File "database_script.py", line 52, in <module>
if __name__ == "__main__": main()
File "database_script.py", line 40, in main
sparql_results = run_sparql_query(sparql_str)
File "database_script.py", line 48, in run_sparql_query
sparql_results = wbi_core.FunctionEngine.execute_sparql_query(sparql_str, endpoint=wbi_config['SPARQL_ENDPOINT_URL'])
AttributeError: module 'wikibaseintegrator.wbi_core' has no attribute 'FunctionEngine'
EDIT 2: The larger issue seemed to be the lack of an install for the SPARQL service since I had gotten it running with WAMP64. I installed a Docker instance and it's been a decent amount easier out of the box (except the export of the WAMP64 version and import into the Docker instance).
OS: Ubuntu 18
Python: Python 3.6
MLflow: 1.4
I'm trying to get MLflow Projects to run. Here is my project:
MLflow
conda.yaml
main.py
prep_data.py
learn.py
List item
The project is heavily based up on this repo: https://github.com/mlflow/mlflow/tree/master/examples/multistep_workflow
I'm trying to run both the prep_data and learn scripts using MLflow Projects and the main.py script as an entry point.
For execution I use the following command: mlflow run . -P experiment_name=testproject
But I get the following Error:
Traceback (most recent call last):
File "prep_data.py", line 126, in <module>
prep_data()
File "/home/ubuntu/venv/lib/python3.6/site-packages/click/core.py", line 764, in __call__
return self.main(*args, **kwargs)
File "/home/ubuntu/venv/lib/python3.6/site-packages/click/core.py", line 717, in main
rv = self.invoke(ctx)
File "/home/ubuntu/venv/lib/python3.6/site-packages/click/core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/ubuntu/venv/lib/python3.6/site-packages/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "prep_data.py", line 65, in prep_data
with mlflow.start_run() as active_run:
File "/home/ubuntu/venv/lib/python3.6/site-packages/mlflow/tracking/fluent.py", line 129, in start_run
"arguments".format(existing_run_id))
mlflow.exceptions.MlflowException: Cannot start run with ID 405b83bbb61046afa83b8dcd71b4db14 because active run ID does not match environment run ID. Make sure --experiment-name or --experiment-id matches experiment set with set_experiment(), or just use command-line arguments
Traceback (most recent call last):
File "main.py", line 75, in <module>
workflow()
File "/home/ubuntu/venv/lib/python3.6/site-packages/click/core.py", line 764, in __call__
return self.main(*args, **kwargs)
File "/home/ubuntu/venv/lib/python3.6/site-packages/click/core.py", line 717, in main
rv = self.invoke(ctx)
File "/home/ubuntu/venv/lib/python3.6/site-packages/click/core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/ubuntu/venv/lib/python3.6/site-packages/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "main.py", line 61, in workflow
}, experiment_name)
File "main.py", line 40, in _get_or_run
submitted_run = mlflow.run('.', entry_point=entry_point, parameters=params)
File "/home/ubuntu/venv/lib/python3.6/site-packages/mlflow/projects/__init__.py", line 287, in run
_wait_for(submitted_run_obj)
File "/home/ubuntu/venv/lib/python3.6/site-packages/mlflow/projects/__init__.py", line 304, in _wait_for
raise ExecutionException("Run (ID '%s') failed" % run_id)
mlflow.exceptions.ExecutionException: Run (ID '405b83bbb61046afa83b8dcd71b4db14') failed
2019/11/22 18:51:59 ERROR mlflow.cli: === Run (ID '62c229b2d9194b569a7b2bfc14338800') failed ===
I'm not sure if I understand the error correctly but it seems like it's saying I am using multiple experiments. However I'm fairly certain I am only using 1 (testproject).
Browsing SO and Github issues suggested I'd should set the environment variable MLFLOW_TRACKING_URI but it wasn't stated on how to set that. Thus I tried two different ways:
1) exporting it before running the MLflow project: $ export MLFLOW_TRACKING_URI='http://127.0.0.1:5099'
2) setting it at the beginning of my main.py script using python: os.environ['MLFLOW_TRACKING_URI'] = 'http://127.0.0.1:5099'
Neither had any effect.
Here you can see my project:
main.py
import os
import click
import mlflow
from mlflow.entities import RunStatus
def _already_ran(entry_point, params, experiment_name):
# experiment = mlflow.get_experiment_by_name('{}_{}'.format(experiment_name, entry_point))
experiment = mlflow.get_experiment_by_name(experiment_name)
if experiment == None:
return None
experiment_id = experiment.experiment_id
client = mlflow.tracking.MlflowClient()
all_run_infos = reversed(client.list_run_infos(experiment_id))
match_failed = False
for run_info in all_run_infos
full_run = client.get_run(run_info.run_id)
for p_key, p_val in params:
run_value = full_run.data.params.get(p_key)
if run_value != p_val:
match_failed = True
break
if match_failed:
continue
if run_info.to_proto().status != RunStatus.FINISHED:
continue
return client.get_run(run_info.run_id)
return None
def _get_or_run(entry_point, params, experiment_name, use_cache=True):
existing_run = _already_ran(entry_point, params, experiment_name)
if use_cache and existing_run:
return existing_run
submitted_run = mlflow.run('.', entry_point=entry_point, parameters=params)
return mlflow.tracking.MlflowClient().get_run(submitted_run.run_id)
#click.command()
#click.option("--experiment-name")
#click.option('--prep-data-time-avg', default='placeholder')
#click.option('--prep-data-sensor-id', default='placeholder')
#click.option('--learn-epochs', default=100, type=int)
#click.option('--learn-neurons', default=5, type=int)
#click.option('--learn-layers', default=2, type=int)
def workflow(experiment_name, prep_data_time_avg, prep_data_sensor_id, learn_epochs, learn_neurons, learn_layers):
# mlflow.set_tracking_uri('http://127.0.0.1:5099')
# mlflow.set_experiment(experiment_name)
# with mlflow.start_run() as active_run:
data_run = _get_or_run('prep_data', {
'time_avg': prep_data_time_avg,
'sensor_id':prep_data_sensor_id,
'experiment_name': experiment_name
}, experiment_name)
learn_run = _get_or_run('learn', {
'epochs': learn_epochs,
'neurons': learn_neurons,
'layers': learn_layers,
'prep_data_run_id': data_run.run_id,
'experiment_name': experiment_name,
}, experiment_name)
if __name__ == '__main__':
# os.environ['MLFLOW_TRACKING_URI'] = 'http://127.0.0.1:5099'
workflow()
prep_data.py
#click.command()
#click.option("--experiment-name")
#click.option('--time-avg', default='placeholder')
#click.option('--sensor-id', default='placeholder')
def prep_data(experiment_name, time_avg, sensor_id):
mlflow.set_experiment(experiment_name)
with mlflow.start_run() as active_run:
# logic code of prep_data
if __name__ == '__main__':
prep_data()
I'm happy about any ideas on how to fix this issue.
Thank you very much!
Cheers,
Raphael
You need to provide the same experiment name to the mlflow CLI:
mlflow run . -P experiment_name=testproject --experiment-name testproject
For more details:
https://www.mlflow.org/docs/latest/cli.html#mlflow-run
I am running video player file in python 3 that has the following imports
import os
import time
import wx
import MplayerCtrl as mpc
import wx.lib.buttons as buttons
I get this the first time:
Traceback (most recent call last):
File "videoplayer.py", line 3, in <module>
import wx
ImportError: No module named 'wx'
When I try to install wx using pip3 install wx , this happens:
Downloading/unpacking wx
Downloading wx-3.0.3.tar.gz (41.8MB): 17.1MB downloaded
Cleaning up...
Exception:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/pip/basecommand.py", line 122, in main
status = self.run(options, args)
File "/usr/lib/python3/dist-packages/pip/commands/install.py", line 278, in run
requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
File "/usr/lib/python3/dist-packages/pip/req.py", line 1198, in prepare_files
do_download,
File "/usr/lib/python3/dist-packages/pip/req.py", line 1376, in unpack_url
self.session,
File "/usr/lib/python3/dist-packages/pip/download.py", line 572, in unpack_http_url
download_hash = _download_url(resp, link, temp_location)
File "/usr/lib/python3/dist-packages/pip/download.py", line 433, in _download_url
for chunk in resp_read(4096):
File "/usr/lib/python3/dist-packages/pip/download.py", line 421, in resp_read
chunk_size, decode_content=False):
File "/usr/share/python-wheels/urllib3-1.7.1-py2.py3-none-any.whl/urllib3/response.py", line 225, in stream
data = self.read(amt=amt, decode_content=decode_content)
File "/usr/share/python-wheels/urllib3-1.7.1-py2.py3-none-any.whl/urllib3/response.py", line 174, in read
data = self._fp.read(amt)
File "/usr/lib/python3.4/http/client.py", line 500, in read
return super(HTTPResponse, self).read(amt)
File "/usr/lib/python3.4/http/client.py", line 539, in readinto
n = self.fp.readinto(b)
File "/usr/lib/python3.4/socket.py", line 374, in readinto
return self._sock.recv_into(b)
File "/usr/lib/python3.4/ssl.py", line 769, in recv_into
return self.read(nbytes, buffer)
File "/usr/lib/python3.4/ssl.py", line 641, in read
v = self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out
Storing debug log for failure in /home/cc/.pip/pip.log
How can I install wx in python3 without incurring this error?
Use the following to install python 3 wxpython phoenix.
pip3 install -U --pre --trusted-host wxpython.org -f http://wxpython.org/Phoenix/snapshot-builds/ wxPython_Phoenix
It seems that pylint on MacOS is not doing anything at all. Here is what I get. I did install pylint by doing pip install pylint
$ pylint tunnel.py
No config file found, using default configuration
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pylint/lint.py", line 910, in get_ast
return MANAGER.ast_from_file(filepath, modname, source=True)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/astroid/manager.py", line 112, in ast_from_file
return AstroidBuilder(self).file_build(filepath, modname)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/astroid/builder.py", line 134, in file_build
module = self._data_build(data, modname, path)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/astroid/builder.py", line 177, in _data_build
module = rebuilder.visit_module(node, modname, node_file, package)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/astroid/rebuilder.py", line 148, in visit_module
newnode.body = [self.visit(child, newnode) for child in node.body]
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/astroid/rebuilder.py", line 148, in <listcomp>
newnode.body = [self.visit(child, newnode) for child in node.body]
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/astroid/rebuilder.py", line 161, in visit
return self._transform(visit_method(node, parent))
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/astroid/rebuilder.py", line 238, in visit_assign
newnode.value = self.visit(node.value, newnode)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/astroid/rebuilder.py", line 161, in visit
return self._transform(visit_method(node, parent))
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/astroid/rebuilder.py", line 331, in visit_callfunc
if node.starargs is not None:
AttributeError: 'Call' object has no attribute 'starargs'
************* Module temp.test
F: 1, 0: <class 'AttributeError'>: 'Call' object has no attribute 'starargs' (astroid-error)
You're mentioning that you're using pylint 1.4.4, which is quite old and won't work with Python 3.5.
You should upgrade to the latest releases of pylint/astroid, e.g. by doing pip install -U pylint.