PythonAnywhere "Cannot import name dateparse" - pythonanywhere

I am following instructions from this site.
I am doing this in PythonAnywhere.
When I run this code:
>>> from provider.oauth2.models import Client
>>> from django.contrib.auth.models import User
>>> u = User.objects.get(id=1)
>>> c = Client(user=u, name="mysite client", client_type=1,url="http://ianalexandr.com")
>>> c.save()
>>> c.client_id
'd63f53a7a6cceba04db5'
>>> c.client_secret
'afe899288b9ac4127d57f2f12ac5a49d839364dc'
I get this error:
line 5, in <module>
from django.utils import dateparse
ImportError: cannot import name dateparse
I am not sure if PythonAnywhere does have dateparse in its library.
and if not, then how can i include dateparse?

Your version of Django is too old. utils.dateparse was introduced in 1.4.
Version 1.3 is almost ancient, and not supported anymore by the Django developers (that is, there will be no security updates).
Consider upgrading to a more recent version if you can. Upgrading to 1.4 (with long term support) will break the least, or upgrade to 1.7 which is the most recent version, but may break most old code.
Edit
I just saw Glenn's note; that explains how you can work around this problem, since the current 1.3 version appears to be pretty much fixed.

Related

AttributeError: module 'torchtext' has no attribute 'legacy'

I am trying to use torchtext to process test data, however, I get the error: "AttributeError: module 'torchtext' has no attribute 'legacy'", when I run the following code. Can anyone please guide me what the issue here? I am using python 3.10.4. Thanks
import pandas as pd
import torch
import torchtext
import spacy
def prep_data(file_path):
TEXT=torchtext.legacy.data.Field(tokenize='spacy', tokenizer_language='en_core_web_sm')
LABEL=torchtext.legacy.data.LabelField(dtype=torch.long)
fields=[('clean_text', TEXT), ('label',LABEL)]
dataset = torchtext.legacy.data.TabularDataset(
path=file_path, format='csv',
skip_header=True, fields=fields)
print(dataset.examples[0])
if __name__=="__main__":
train_path='./data/train.csv'
test_path='./data/test.csv'
prep_data(train_path)
I addressed the same issue by updating the torchtext.
pip install torchtext==0.9
I also had the same issue. I solved my problem by using a pytorch stable version You are probably using versions 0.10, and 0.11. These were the versions using legacy.
Please update to the latest versions 0.13 and 0.14.
pip install torchtext==<version>

ImportError: cannot import name 'escape' from 'cgi'

I'm getting the error message "ImportError: cannot import name 'escape' from 'cgi'" when I try to use following code in pycharm:
import nltk
parser = nltk.ChartParser(grammar, trace=0)
for tree in parser.parse(sent):
print(tree)
tree.pretty_print(unicodelines=True)
What should I do to correct it?
cgi.escape() has been removed in python 3.8. Quoting from here,
parse_qs, parse_qsl, and escape are removed from the cgi module. They
are deprecated in Python 3.2 or older. They should be imported from
the urllib.parse and html modules instead.
Since you are importing a third-party module, try using a lower python version.
I have updated the supervisor package version into:
supervisor==4.1.0
https://pypi.org/project/supervisor/4.1.0/
[Fixed a Python 3.8 compatibility issue caused by the removal of cgi.escape(). Patch by Mattia Procopio.]
problem solved.
You can use html.escape instead of cgi.escape.
It worked for me

ModuleNotFoundError: No module named 'windows'

I'm working on a project and I need to use the PyMouse module.
pip install pymouse
installed pymouse correctly, so I assumed all was fine.
However, when importing PyMouse:
from pymouse import PyMouse
I got the following error running my program:
Traceback (most recent call last):
File "4opeenrij.py", line 1, in <module>
from pymouse import PyMouseEvent
File "C:\Users\lcdew\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pymouse\__init__.py", line 92, in <module>
from windows import PyMouse, PyMouseEvent
ModuleNotFoundError: No module named 'windows'
I can't seem to figure out what might cause this error message. Any help would be much appreciated.
Additional info:
I'm using Python 3.7 32 bit
Current pip version: 18.1
I have Windows 10
working on a 64-bit operating system
I had I look into this and became puzzled at first, so looked deeper.
It turns out that pymouse is absolutely full of errors. More that I bothered to find.
The error you got is just one of many errors caused by bad coding.
The code says:
from windows import PyMouse, PyMouseEvent
And it should say:
from .windows import PyMouse, PyMouseEvent
Also, PyUserInput, a sister package that is free from the pymouse errors, requires pyhook, which is unsupported by python 3. After a lot of looking around, the conclusion that there is no way around the problems found, except maybe installing a really early version.
You could also try the keyboard module.
You might want to take a look at pynput module. It works on python 3.8, doesn't have any incompatible dependencies, and doesn't seem to have any errors. Once you have the module installed, this page gives some good examples of various ways to manage the mouse.

ModuleNotFoundError: Python 3.6 does not find modules while Python 3.5 does

I wanted to upgrade my python version from 3.5 to 3.6. Since I am using WinPython, I have downloaded and installed the recent version just as I did it before with version 3.5.
However, if I use version 3.6 I get a ModuleNotFoundError whenever I import a self-created module. A minimal example: I created a file t1.py that contains only a pass statement and a file t2.py containing the following code:
import t1
print("done")
Both files are in the same folder D:\MyProject\src. Now when I run the file with python 3.5, everything works fine:
'C:\Program Files\WinPython-64bit-3.5.1.2\python-3.5.1.amd64\python.exe' D:\MyProject\src\t2.py
done
However, with python 3.6 I get
'C:\Program Files\WinPython-64bit-3.6.0.1Qt5\python-3.6.0.amd64\python.exe' D:\MyProject\src\t2.py
Traceback (most recent call last):
File "D:\MyProject\src\t2.py", line 6, in <module>
import t1
ModuleNotFoundError: No module named 't1'
I ran out of ideas what the issue could be and would appreciate new inspiration.
Would this work ? in t2.py
import os
__path__=[os.path.dirname(os.path.abspath(__file__))]
from . import t1
print("t2 done")
Python-3.6 changes its way of working, with the "python._pth" file next to python.exe (instead of "pyvenv.cfg" in previous versions)
If you don't want to modify your source, then you have to add "D:\MyProject\src" line in Python._pth file, or a relative path to it from python._pth location. in my example, it works with:
python36.zip
DLLs
Lib
.
..\test
import site
"http://bugs.python.org/issue29578?#ok_message=msg%20287921%20created%0Aissue%2029578%20message_count%2C%20messages%20edited%20ok&#template=item"
Other, simpler solution if you have no system-installed python: rename the "python._pth" file, next to "python.exe", as "pythonzz._pth"
The Python "Windows" maintainer just wrote that the simpler solution should be ok also with Python-3.6.0.

SVG support missing in PySide 1.2.1

With PySide 1.2.1 installed through the Canopy Package Manager, I get the following set of supported image formats:
>>> from PySide import QtGui
>>> QtGui.QImageReader.supportedImageFormats()
[PySide.QtCore.QByteArray('bmp'),
PySide.QtCore.QByteArray('pbm'),
PySide.QtCore.QByteArray('pgm'),
PySide.QtCore.QByteArray('png'),
PySide.QtCore.QByteArray('ppm'),
PySide.QtCore.QByteArray('xbm'),
PySide.QtCore.QByteArray('xpm')]
If I downgrade to PySide 1.1.0, I get the following:
>>> from PySide import QtGui
>>> QtGui.QImageReader.supportedImageFormats()
[PySide.QtCore.QByteArray('bmp'),
PySide.QtCore.QByteArray('gif'),
PySide.QtCore.QByteArray('ico'),
PySide.QtCore.QByteArray('jpeg'),
PySide.QtCore.QByteArray('jpg'),
PySide.QtCore.QByteArray('mng'),
PySide.QtCore.QByteArray('pbm'),
PySide.QtCore.QByteArray('pgm'),
PySide.QtCore.QByteArray('png'),
PySide.QtCore.QByteArray('ppm'),
PySide.QtCore.QByteArray('svg'),
PySide.QtCore.QByteArray('svgz'),
PySide.QtCore.QByteArray('tif'),
PySide.QtCore.QByteArray('tiff'),
PySide.QtCore.QByteArray('xbm'),
PySide.QtCore.QByteArray('xpm')]
Is there some extra configuration required to restore the missing formats?
I'm running Canopy v1.3.0.1715 on Mac OS X.
The extra image format handlers are distributed as Qt plugins, but it appears that Qt is not able to find them despite the presence of a qt.conf file. We'll get that fixed for a future release, but in the meantime you can workaround the issue by setting the QT_PLUGIN_PATH variable in the environment. For example:
export QT_PLUGIN_PATH=/Applications/Canopy.app/appdata/canopy-1.3.0.1715.macosx-x86_64/Canopy.app/Contents/plugins
[edit]
Actually the plugins fodler is properly found after the application object has been created:
>>> from PySide import QtCore, QtGui
>>> app = QtCore.QCoreApplication([])
>>> import pprint
>>> pprint.pprint(QtGui.QImageReader.supportedImageFormats())
[PySide.QtCore.QByteArray('bmp'),
PySide.QtCore.QByteArray('gif'),
PySide.QtCore.QByteArray('ico'),
PySide.QtCore.QByteArray('jpeg'),
PySide.QtCore.QByteArray('jpg'),
PySide.QtCore.QByteArray('mng'),
PySide.QtCore.QByteArray('pbm'),
PySide.QtCore.QByteArray('pgm'),
PySide.QtCore.QByteArray('png'),
PySide.QtCore.QByteArray('ppm'),
PySide.QtCore.QByteArray('tga'),
PySide.QtCore.QByteArray('tif'),
PySide.QtCore.QByteArray('tiff'),
PySide.QtCore.QByteArray('xbm'),
PySide.QtCore.QByteArray('xpm')]
>>>
But the svg format still seems to be MIA. I'll check into that further.