I was giving a look at the "Learn Python The Hard Way" tutorial and when it told me to try it out by typing Python in Powershell after I installed it just kept giving me this:
PS C:\Users\Zach> python
Traceback (most recent call last):
File "C:\Python27\lib\site.py", line 548, in <module>
main()
File "C:\Python27\lib\site.py", line 530, in main
known_paths = addusersitepackages(known_paths)
File "C:\Python27\lib\site.py", line 266, in addusersitepackages
user_site = getusersitepackages()
File "C:\Python27\lib\site.py", line 241, in getusersitepackages
user_base = getuserbase() # this will also set USER_BASE
File "C:\Python27\lib\site.py", line 231, in getuserbase
USER_BASE = get_config_var('userbase')
File "C:\Python27\lib\sysconfig.py", line 516, in get_config_var
return get_config_vars().get(name)
File "C:\Python27\lib\sysconfig.py", line 449, in get_config_vars
import re
File "C:\Python27\lib\re.py", line 105, in <module>
import sre_compile
File "C:\Python27\lib\sre_compile.py", line 14, in <module>
import sre_parse
File "C:\Python27\lib\sre_parse.py", line 17, in <module>
from sre_constants import *
File "C:\Python27\lib\sre_constants.py", line 18, in <module>
from _sre import MAXREPEAT
ImportError: cannot import name MAXREPEAT
I also tried running through the command prompt and got the same error. I've installed and uninstalled python about 3 times and have done a few reboots to no avail. I am very new to python and I'm confused on what to do here. I would also appreciate any links to other python tutorials.
In this case, from my understanding, you have no modules called "MAXREPEAT" or you(or the installer) have installed it somewhere wrong. A reinstallation or redirecting the path should get it to work.
Related
I am creating a jupyter notebook programatically with Python. Using the nbformat library.
Once I create the file:
fname = f'{filename}.ipynb'
with open(fname, 'w') as notebook:
nbf.write(nb, notebook)
I open the file with Jupyter Lab and get the following error in the terminal console:
Fatal Python error: init_import_size: Failed to import the site module
Python runtime state: initialized
Traceback (most recent call last):
File "/Users/sota/anaconda3/lib/python3.8/site.py", line 580, in <module>
main()
File "/Users/sota/anaconda3/lib/python3.8/site.py", line 567, in main
known_paths = addsitepackages(known_paths)
File "/Users/sota/anaconda3/lib/python3.8/site.py", line 350, in addsitepackages
addsitedir(sitedir, known_paths)
File "/Users/sota/anaconda3/lib/python3.8/site.py", line 208, in addsitedir
addpackage(sitedir, name, known_paths)
File "/Users/sota/anaconda3/lib/python3.8/site.py", line 169, in addpackage
exec(line)
File "<string>", line 1, in <module>
File "/Users/sota/anaconda3/lib/python3.8/importlib/util.py", line 14, in <module>
from contextlib import contextmanager
File "/Users/sota/anaconda3/lib/python3.8/contextlib.py", line 5, in <module>
from collections import deque
File "/Users/sota/anaconda3/lib/python3.8/collections/__init__.py", line 24, in <module>
import heapq as _heapq
File "/Users/sota/anaconda3/lib/python3.8/heapq.py", line 581, in <module>
from _heapq import *
KeyboardInterrupt
I have been researching a lot, but I don't get to find the error... some guidance on why this is happening?
PD: the only solution I've found so far is openinig the notebook with vscode and somehow, the notebook gets fixed.
It was actually a very newbie error. I had written the names of the folders with accented characters. Therefore, Jupyter Lab couldn't recognize correctly the files.
I'm working on a Rally reporting tool for my team in Python, and I'm trying to package it using cx-freeze. I'm getting a ModuleNotFound error, and I'm wondering if it's because pygal isn't supported by cx-freeze (really hoping this isn't the case because I'd have to rewrite a lot of things)
celinaperalta$ /Users/celinaperalta/Documents/NYLTesting/rally-exports/build/exe.macosx-10.9-x86_64-3.7/RallyGUI ; exit;
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/cx_Freeze/initscripts/__startup__.py", line 40, in run
module.run()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/cx_Freeze/initscripts/Console.py", line 37, in run
exec(code, {'__name__': '__main__'})
File "RallyGUI.py", line 8, in <module>
File "/Users/celinaperalta/Documents/NYLTesting/rally-exports/build/exe.macosx-10.9-x86_64-3.7/RallyReportTool.py", line 7, in <module>
import pygal
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pygal/__init__.py", line 28, in <module>
import pkg_resources
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pkg_resources/__init__.py", line 959, in <module>
class Environment:
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pkg_resources/__init__.py", line 963, in Environment
self, search_path=None, platform=get_supported_platform(),
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pkg_resources/__init__.py", line 190, in get_supported_platform
plat = get_build_platform()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pkg_resources/__init__.py", line 395, in get_build_platform
plat = get_platform()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/sysconfig.py", line 675, in get_platform
get_config_vars(),
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/sysconfig.py", line 551, in get_config_vars
_init_posix(_CONFIG_VARS)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/sysconfig.py", line 422, in _init_posix
_temp = __import__(name, globals(), locals(), ['build_time_vars'], 0)
ModuleNotFoundError: No module named '_sysconfigdata_m_darwin_darwin'
cx_freeze does not include all the packages automatically. When you find ModuleNotFoundError, you need to inlcude the module explicitly in your setup like -
build_exe_options = {'packages': ['_sysconfigdata_m_darwin_darwin']}
Yesterday I installed the mysql connector package, today I can't start python anymore. Anacona won't start nor directly Python 3.6. The Anaconda prompt delivered:
Microsoft Windows [Version 10.0.17134.48]
(c) 2018 Microsoft Corporation. Alle Rechte vorbehalten.
C:\Users\ric22>python.exe -m idlelib.idle
Error processing line 1 of C:\Users\ric22\AppData\Local\Programs\Python\Python36\lib\site-packages\protobuf-3.5.2.post1-py3.6-nspkg.pth:
Failed to import the site module
Traceback (most recent call last):
File "C:\Users\ric22\AppData\Local\Programs\Python\Python36\lib\site.py", line 168, in addpackage
exec(line)
File "<string>", line 1, in <module>
File "D:\Programme\Anaconda\pkgs\sqlalchemy-1.1.13-py36h5948d12_0\Lib\site-packages\sqlalchemy\dialects\mysql\types.py", line 9, in <module>
from ... import exc, util
ImportError: attempted relative import with no known parent package
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\ric22\AppData\Local\Programs\Python\Python36\lib\site.py", line 544, in <module>
main()
File "C:\Users\ric22\AppData\Local\Programs\Python\Python36\lib\site.py", line 531, in main
known_paths = addsitepackages(known_paths)
File "C:\Users\ric22\AppData\Local\Programs\Python\Python36\lib\site.py", line 328, in addsitepackages
addsitedir(sitedir, known_paths)
File "C:\Users\ric22\AppData\Local\Programs\Python\Python36\lib\site.py", line 207, in addsitedir
addpackage(sitedir, name, known_paths)
File "C:\Users\ric22\AppData\Local\Programs\Python\Python36\lib\site.py", line 178, in addpackage
import traceback
File "C:\Users\ric22\AppData\Local\Programs\Python\Python36\lib\traceback.py", line 5, in <module>
import linecache
File "C:\Users\ric22\AppData\Local\Programs\Python\Python36\lib\linecache.py", line 8, in <module>
import functools
File "C:\Users\ric22\AppData\Local\Programs\Python\Python36\lib\functools.py", line 22, in <module>
from types import MappingProxyType
File "D:\Programme\Anaconda\pkgs\sqlalchemy-1.1.13-py36h5948d12_0\Lib\site-packages\sqlalchemy\dialects\mysql\types.py", line 9, in <module>
from ... import exc, util
ImportError: attempted relative import with no known parent package
Does anyone have an idea how to make Python run again? Thanks in Advance
Ric
Thanks amphibient,
I had set this environment variable 'cause I couldn't make mysql package work on Spyder:
D:\Programme\Anaconda\pkgs\sqlalchemy-1.1.13-py36h5948d12_0\Lib\site-packages\sqlalchemy\dialects\mysql\types.py
(Now I see .py is obviously no folder ;))
This messed everything up. I removed it and installed the package with
conda install mysql-connector-python typed into conda path.
Now everything works.
I'm trying to perform web scraping with BS4 and then do some algebra work with the results in Sage 6.2 (in Lion 10.7.5). I assumed that /Applications/Sage-6.2.app/Contents/Resources/sage/sage -i beautifulsoup4 would work, but the result is
Attempting to download package beautifulsoup4
>>> Checking online list of optional packages.
[Traceback (most recent call last):
File "<stdin>", line 35, in <module>
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python/urllib.py", line 240, in retrieve
fp = self.open(url, data)
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python/urllib.py", line 208, in open
return getattr(self, name)(url)
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python/urllib.py", line 359, in open_http
return self.http_error(url, fp, errcode, errmsg, headers)
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python/urllib.py", line 376, in http_error
return self.http_error_default(url, fp, errcode, errmsg, headers)
File "<stdin>", line 17, in http_error_default
IOError: [Errno 404] Not Found: '//www.sagemath.org/spkg/optional/list'
Error: failed to download http://www.sagemath.org/spkg/optional/list, aborting
Next, I tried /Applications/Sage-6.2.app/Contents/Resources/sage/sage -sh <<< "easy_install --verbose pip" to get bs4 via pip. That succeeded; however /Applications/Sage-6.2.app/Contents/Resources/sage/local/bin/pip2.7 install beautifulsoup4 failed with error message
Traceback (most recent call last):
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site.py", line 548, in <module>
main()
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site.py", line 530, in main
known_paths = addusersitepackages(known_paths)
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site.py", line 266, in addusersitepackages
user_site = getusersitepackages()
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site.py", line 241, in getusersitepackages
user_base = getuserbase() # this will also set USER_BASE
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/site.py", line 231, in getuserbase
USER_BASE = get_config_var('userbase')
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/sysconfig.py", line 516, in get_config_var
return get_config_vars().get(name)
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/sysconfig.py", line 449, in get_config_vars
import re
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/re.py", line 105, in <module>
import sre_compile
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/sre_compile.py", line 14, in <module>
import sre_parse
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/sre_parse.py", line 17, in <module>
from sre_constants import *
File "/Applications/Sage-6.2.app/Contents/Resources/sage/local/lib/python2.7/sre_constants.py", line 18, in <module>
from _sre import MAXREPEAT
ImportError: cannot import name MAXREPEAT
Next, I tried upgrading to Sage 6.6. That went smoothly, as did the installation of bs4. However, when I opened the notebook, I was unable to run code cells, because the "Shift-Enter" command only registered as "Enter" and gave me a new line instead of evaluating the code. Additionally, there was no "evaluate" button. Any recommendations to solve any of these issues would be greatly appreciated.
Unfortunately, Sage has changed how it handles optional packages like BS so that older versions may not be able to use them. You can always go to a mirror, though, like http://mirrors.mit.edu/sage/spkg/optional/ download it, and put it in your (old Sage's) optional spkg directory and try doing sage -i path/to/file.
As to the notebook issue, that should be a matter of doing a "hard cache reset" in the browser due to different jQuery versions, see e.g. here.
Problem using MySQLdb after installing MySQLdb-python. I followed the instructions I followed the instruction that had me delete the build and delete the egg then modify the my_config and then run the install again. I also tried installing the 64 bit version still no luck
Traceback (most recent call last):
File "/Users/nick.leclair/Documents/Aptana Studio 3 Workspace/Tester/driveByScript.py", line 1, in <module>
import MySQLdb
File "build/bdist.macosx-10.9-intel/egg/MySQLdb/__init__.py", line 19, in <module>
File "build/bdist.macosx-10.9-intel/egg/_mysql.py", line 7, in <module>
File "build/bdist.macosx-10.9-intel/egg/_mysql.py", line 4, in __bootstrap__
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 882, in resource_filenameself, resource_name
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 1351, in get_resource_filename self._extract_resource(manager,self._eager_to_zip(name))
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 1382, in _extract_resource outf, tmpnam = _mkstemp(".$extract", dir=os.path.dirname(real_path))
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 2576, in _mkstemp
from tempfile import mkstemp
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 35, in <module>
ImportError: cannot import name Random
Problem solved, it was problem with Aptana not picking up the new library.