No user_config.py - python

We have an internal wiki and I want to use pywikibot to get some data from it. Installed it from pip but when I import it I get:
>>> import pywikibot
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.7/site-packages/pywikibot/__init__.py",
line 25, in <module>
from pywikibot.bot import (
File "/usr/local/lib/python3.7/site-packages/pywikibot/bot.py", line
105, in <module>
from pywikibot import config2 as config
File "/usr/local/lib/python3.7/site-packages/pywikibot/config2.py",
line 373, in <module>
base_dir = get_base_dir()
File "/usr/local/lib/python3.7/site-packages/pywikibot/config2.py",
line 367, in get_base_dir
raise RuntimeError(exc_text)
RuntimeError: No user-config.py found in directory '/vagrant'.
Looking here https://www.mediawiki.org/wiki/Manual:Pywikibot/Installation#Configure_Pywikibot
I see a reference to pwb.py, but that does not exist in
/usr/local/lib/python3.7/site-packages/pywikibot.
What am I missing here?
Thanks!

Installing pywikibot from pip currently only installs the library part. The pwb.py and related console scripts are not included in the PyPI package. That means that you'll need to create the user-config.py manually or download the scripts in some other way.
I believe most pywikibot users just clone the git repo. The general process would be something like this:
git clone https://github.com/wikimedia/pywikibot.git --depth 1
python3 -m pip install -U setuptools
python3 -m pip install -e pywikibot/
cd pywikibot/
python3 pwb.py generate_family_file.py https://url.to.your/wiki/api.php? mywikiname
python3 pwb.py generate_user_files.py
# follow the prompts

Adding generate_family_file is in active development:
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/634544
The other two script will follow later I guess.

Related

python generating netaddr error when running code

I am trying to get a piece of software called Probemon working and have come up with an error when I try to run it.
As I have both python2 and python3 installed (as per default installation) so I am running the command:
root#root:~/probemon/src$ python2 ./probemon.py -h
Traceback (most recent call last):
File "./probemon.py", line 11, in <module>
import netaddr
File "/usr/local/lib/python2.7/dist-packages/netaddr-0.8.0-py2.7.egg/netaddr/__init__.py", line 18, in <module>
from netaddr.core import (AddrConversionError, AddrFormatError,
File "/usr/local/lib/python2.7/dist-packages/netaddr-0.8.0-py2.7.egg/netaddr/core.py", line 11, in <module>
from netaddr.compat import _callable, _iter_dict_keys
File "/usr/local/lib/python2.7/dist-packages/netaddr-0.8.0-py2.7.egg/netaddr/compat.py", line 93, in <module>
import importlib_resources as _importlib_resources
File "/usr/local/lib/python2.7/dist-packages/importlib_resources-3.0.0-py2.7.egg/importlib_resources/__init__.py", line 5, in <module>
from ._common import (
File "/usr/local/lib/python2.7/dist-packages/importlib_resources-3.0.0-py2.7.egg/importlib_resources/_common.py", line 9, in <module>
from ._compat import (
File "/usr/local/lib/python2.7/dist-packages/importlib_resources-3.0.0-py2.7.egg/importlib_resources/_compat.py", line 42, in <module>
from zipp import Path as ZipPath # type: ignore
File "/usr/local/lib/python2.7/dist-packages/zipp-3.1.0-py2.7.egg/zipp.py", line 217
def open(self, mode='r', *args, pwd=None, **kwargs):
^
SyntaxError: invalid syntax
I am not sure what this error is trying to indicate...
Prior to this I have run these commands:
git clone https://github.com/drkjam/netaddr
cd netaddr
sudo python setup.py install
cd
git clone https://github.com/secdev/scapy.git
cd scapy
sudo python setup.py install
to ensure both netaddr and scapy dependencies are installed
To me, the error looks to have a problem with line 11 import netaddr however IF this is the case, I have already installed this, so I am not sure where the problem lies.
I have also tried running sudo python setup.py install for netaddr and scapy as sudo **python2** setup.py install in their respective directories just in case this made any difference which it did not.
Can anyone tell me what what the error is indicating please.
Thanks

Installing libLAS on docker python - No such file or directory

I'm working in python in docker, and I need to add the package libLAS.
I usually just add a simple line to my dockerfile, for libLAS it would is:
Run pip install liblas
Docker seems to be able to build the image, but when I run a python script with the line:
import liblas
it gives the error:
Traceback (most recent call last):
File "/src/test.py", line 6, in <module>
import liblas
File "/usr/local/lib/python2.7/dist-packages/liblas/__init__.py", line 2, in <module>
from .core import get_version
File "/usr/local/lib/python2.7/dist-packages/liblas/core.py", line 158, in <module>
las = ctypes.CDLL(lib_name)
File "/usr/lib/python2.7/ctypes/__init__.py", line 365, in __init__
self._handle = _dlopen(self._name, mode)
OSError: liblas_c.so.3: cannot open shared object file: No such file or directory
I don't know what this error message means. Can someone please tell me how I can use liblas in python on docker?
You can add RUN apt-get -y install liblas-c3 in your Dockerfile and then Docker build . to install it.
You are just installing the python bindings. You need also to install liblas itself. If you are using Ubuntu/Debian, try
$ apt-get install liblas-c3

Passing Python3 to virtualenvwrapper throws up ImportError

I'm trying to use the virtualenvwrapper to make a python 3 based virtualenv. However,I'm when I pass the optional interpreter argument, I'm seeing this error. I'm running Ubuntu 15.04. I tried reinstalling virtualenv and virtualenvwrapper without success. Thanks for all your help!
$ mkvirtualenv scriptcutter --python=/usr/bin/python3
Running virtualenv with interpreter /usr/bin/python3
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 8, in <module>
import base64
File "/usr/lib/python3.4/base64.py", line 9, in <module>
import re
File "/usr/lib/python3.4/re.py", line 336, in <module>
import copyreg
File "/usr/local/lib/python2.7/dist-packages/copyreg/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 53, in apport_excepthook
if not enabled():
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 24, in enabled
import re
File "/usr/lib/python3.4/re.py", line 336, in <module>
import copyreg
File "/usr/local/lib/python2.7/dist-packages/copyreg/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
Original exception was:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 8, in <module>
import base64
File "/usr/lib/python3.4/base64.py", line 9, in <module>
import re
File "/usr/lib/python3.4/re.py", line 336, in <module>
import copyreg
File "/usr/local/lib/python2.7/dist-packages/copyreg/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
I come across same issue, but after I downgrade virtualenv to 12.0.2, this problem disappears.
This is sort of a workaround for now.
Create a virtualenv using pyvenv.
# install pyvenv on Ubuntu
sudo apt-get install python3-venv
To minimize disruption in your normal workflow, pass a destination directory that is the same as the one used by virtualenvwrapper Like so,
pyvenv example ~/.virtualenvs/example
This is automatically working with workon and cdproject commands. I don't use much else that is provided by virtualenvwrapper
Hope this helps.
You can upgrade to the most recent version of virtualenv, with:
sudo pip install --upgrade https://github.com/pypa/virtualenv/archive/master.zip
virtualenv --version
# Returns 15.2.0.dev0 when I ran it
The following command then works:
mkvirtualenv scriptcutter --python=/usr/bin/python3
Apparently, the develop branch was dropped, so the URL with "develop" will no longer work. My answer was based off of #pjotr_dolphin's comment, with the URL updated.

pyjamas - pyjsbuild error due to DistributionNotFound

I am trying to build the HelloWorld example page from the Pyjamas example folder. However I am receiving this error when I run: sudo pyjsbuild helloworld.py. This error seems pretty universal to python as it seems to be related to the setup/configuration of my python environment. Any advice on where to look for the problem?
Here is the error
Traceback (most recent call last):
File "/usr/local/bin/pyjsbuild", line 5, in <module>
from pkg_resources import load_entry_point
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 2603, in <module>
working_set.require(__requires__)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 666, in require
needed = self.resolve(parse_requirements(requirements))
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 565, in resolve
raise DistributionNotFound(req) # XXX put more info here
pkg_resources.DistributionNotFound: six
After trying the various answers, it turns out pip was not properly installing the six package, whatever that is. So I ran sudo easy_install pip (--upgrade) to make sure the script configuration was right. It wrote some extra files so I assume that's why my next command sudo pip install six or sudo pip install six --upgrade worked. Now I ran into another error -_-, For anyone looking later: Runtime Error: Top module not found 'hello world'
Edit: The top module error is coming from trying to build into the output folder that is not pyjs/. All I had to do was move the folder up to pyjs/ folder in sitepackages/.

Not able to install Django on windows 7

I am trying to install Django-1.5.5 on windows 7. I have installed it but when I try to punch in "django-admin.py startproject mysite" I get following error:
C:\Users\DIPANSHU>django-admin.py startproject mysite
Traceback (most recent call last):
File "C:\Django-1.5.5\django\bin\django-admin.py", line 2, in <module>
from django.core import management
File "C:\Python27\lib\site-packages\django\core\management\__init__.py",
9, in <module>
from django.core.management.base import BaseCommand, CommandError, han
fault_options
File "C:\Python27\lib\site-packages\django\core\management\base.py", lin
in <module>
from django.utils.encoding import force_str
File "C:\Python27\lib\site-packages\django\utils\encoding.py", line 10,
dule>
from urllib import quote
File "C:\Python27\lib\urllib.py", line 26, in <module>
import socket
File "C:\Python27\lib\socket.py", line 47, in <module>
import _socket
ImportError: DLL load failed: The specified procedure could not be found.
Previously, I tried with Django-1.4.2 but problem was same. I am having Python27.Please assist.
Yups! Finally got it! So here's what I did:
Removed python completely and installed it again.
adjust my PATH environment variable to include paths to the Python executable & additional scripts.
Installed Setuptools
Installed pip using easy_install pip.
Installed Django using pip install django.
Note: If your Python is installed in C:\Python27\, the following paths need to be added to PATH: C:\Python27\;C:\Python27\Scripts;
Reference: https://docs.djangoproject.com/en/dev/howto/windows/
Thanks a lot for your valuable inputs and bearing with me! :-)
I would make sure that DJango is installed by running
python -c "import django; print(django.get_version())"
https://docs.djangoproject.com/en/1.6/intro/tutorial01/
I found the Django tutorial on their site to be very good
Also what exactly are you typing into the command prompt ? You should simply be in directory C:\Users\DIPANSHU> in the command shell
EDIT: you should be in the directory where you installed Django

Categories