Python web scraping stopped working - Invalid File Error - visual-studio

I have been working on a web scraping program and it has recently just stopped working and is giving me the following error.
Traceback (most recent call last):
File "C:/Users/Bob/Desktop/test 3.5.py", line 7, in <module>
with open(saveDB,'rb') as f:
TypeError: invalid file: WindowsPath('Z:/project1/MasterWellDB.txt')
Where Z: is a network drive, but I have also moved the file locally and the error still exists.
I have tried multiple python versions, uninstalled and reinstalled visual studio multiple times and I am still clueless.
Here is my code:
from pathlib import Path
import pickle
# Opening well database
saveDB = Path(r"Z:\project1\MasterWellDB.txt")
#open picked DB if avaiable else remake database
if saveDB.exists():
with open(saveDB,'rb') as f:
wells = pickle.load(f)
print('success!')
Any help would be greatly appreciated. Thanks!

Related

OSError: [WinError 87] The parameter is incorrect: Jupyter & Anaconda

I am using Jupyter notebooks via anaconda. When saving a new notebook to a specific directory, the whole directory becomes inaccessible, showing this error (image and text below). Other directories and the notebooks inside them are still accessible and able to be run. I am able to save new notebooks and run them in other directories no problem.
Error:
Server error: Traceback (most recent call last): File "C:\Users\u1252652.conda\envs\DS011_loss_ratio\lib\site-packages\tornado\web.py", line 1704, in _execute result = await result File "C:\Users\u1252652.conda\envs\DS011_loss_ratio\lib\site-packages\tornado\gen.py", line 234, in wrapper yielded = ctx_run(next, result) File "C:\Users\u1252652.conda\envs\DS011_loss_ratio\lib\site-packages\notebook\services\contents\handlers.py", line 116, in get model = yield maybe_future(self.contents_manager.get( File "C:\Users\u1252652.conda\envs\DS011_loss_ratio\lib\site-packages\notebook\services\contents\filemanager.py", line 435, in get model = self._dir_model(path, content=content) File "C:\Users\u1252652.conda\envs\DS011_loss_ratio\lib\site-packages\notebook\services\contents\filemanager.py", line 309, in _dir_model for name in os.listdir(os_dir): OSError: [WinError 87] The parameter is incorrect: 'C:\Users\u1252652\OneDrive - MMC\Documents\DS011_loss_ratio'
This is strange as i have been working in this directory and saving numerous notebooks to it without error until today. I can delete the notebook that caused it to crash and then it returns to normal and i can run notebooks that were already saved before today.
I am unsure if this is related or not but i also have an issue whereby i have to run python -m ipykernel install --user every time i change to a new environment in anaconda, otherwise the executable remains as that of the last environment i ran that command with. Perhaps this is useful i'm not sure, if anyone had advice with this too i'd be grateful.
I have also tried making a new directory, copying over the contents of the dysfunctional directory, and then making a new notebook from there, however this causes the same error.

Anaconda-Navigator problem loading packages

I am currently on Windows 11 and facing this problem since upgrade. Each time I install anaconda-navigator, on first time opening it runs smoothly however on second time if I open from windows, it opens but gets stuck on environment loading and when I open it from prompt, I get the error below. I do realize that error is from conda-script.py line587 however I don't want to do modifications blindly so need some expert opinion on how to resolve it.
I never faced these issues even on last moment on Windows 10, and I don't know how much windows upgrade is a problem here.
(base) C:\Users\abdul>anaconda-navigator
2021-10-20 19:51:06,740 - ERROR anaconda_api._pip_data_ready:579
C:/Users/abdul/anaconda3/python.exe C:/Users/abdul/anaconda3/Scripts/conda-script.py list --json: Not a conda environment: C:/ProgramData/Anaconda3
Traceback (most recent call last):
File "C:\Users\abdul\anaconda3\lib\site-packages\anaconda_navigator\api\anaconda_api.py", line 587, in _pip_data_ready
channel_urls = set(package['base_url'] for package in output if package['platform'] != 'pypi')
File "C:\Users\abdul\anaconda3\lib\site-packages\anaconda_navigator\api\anaconda_api.py", line 587, in <genexpr>
channel_urls = set(package['base_url'] for package in output if package['platform'] != 'pypi')
TypeError: string indices must be integers

web application using dash in python

I have develop a simple program using dash plotly in spyder but it showing me the following error.
import dash
import dash_core_components as dcc
import dash_html_components as html
app = dash.Dash()
app.layout = html.Div(
html.H1(children='Hello Dash')
)
if __name__ == '__main__':
app.run_server(debug=True)
but it showing me the following error.
Running on http://127.0.0.1:8050/
Debugger PIN: 870-923-677
Traceback (most recent call last):
File "<ipython-input-13-3c5b23764cd8>", line 5, in <module>
app.run_server(debug=True)
File "C:\Users\Hussnain\Anaconda3\lib\site-packages\dash\dash.py", line 1503, in run_server
self.server.run(port=port, debug=debug, **flask_run_options)
File "C:\Users\Hussnain\Anaconda3\lib\site-packages\flask\app.py", line 938, in run
cli.show_server_banner(self.env, self.debug, self.name, False)
File "C:\Users\Hussnain\Anaconda3\lib\site-packages\flask\cli.py", line 629, in show_server_banner
click.echo(message)
File "C:\Users\Hussnain\Anaconda3\lib\site-packages\click\utils.py", line 259, in echo
file.write(message)
UnsupportedOperation: not writable
Spyder has some conflicts using Debug=True. Please run your code inside Visual Studio Code.
For my system: Your code is running fine.
Please tell us if this software swap solved your problem. If not, I will provide further assistance. :)

NLTK v3.2: Unable to nltk.pos_tag()

Hi text mining champions,
I'm using Anaconda with NLTK v3.2 on Windows 10.(client's environment)
When I try to POS tag, I keep getting a URLLIB2 error:
URLError: <urlopen error unknown url type: c>
It seems urllib2 is unable to recognize windows paths? How can I work around this?
The command is simple as:
nltk.pos_tag(nltk.word_tokenize("Hello World"))
edit:
There is a duplicate question, however I think the answers obtained here by manan and alvas are a better fix.
EDITED
This issue has been resolved from NLTK v3.2.1. Upgrading your NLTK version would resolve the issue, e.g. pip install -U nltk.
I faced the same issue and the error encountered was as follows;
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\nltk-3.2-py2.7.egg\nltk\tag\__init__.py", line 110, in pos_tag
tagger = PerceptronTagger()
File "C:\Python27\lib\site-packages\nltk-3.2-py2.7.egg\nltk\tag\perceptron.py", line 141, in __init__
self.load(AP_MODEL_LOC)
File "C:\Python27\lib\site-packages\nltk-3.2-py2.7.egg\nltk\tag\perceptron.py", line 209, in load
self.model.weights, self.tagdict, self.classes = load(loc)
File "C:\Python27\lib\site-packages\nltk-3.2-py2.7.egg\nltk\data.py", line 801, in load
opened_resource = _open(resource_url)
File "C:\Python27\lib\site-packages\nltk-3.2-py2.7.egg\nltk\data.py", line 924, in _open
return urlopen(resource_url)
File "C:\Python27\lib\urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "C:\Python27\lib\urllib2.py", line 391, in open
response = self._open(req, data)
File "C:\Python27\lib\urllib2.py", line 414, in _open
'unknown_open', req)
File "C:\Python27\lib\urllib2.py", line 369, in _call_chain
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 1206, in unknown_open
raise URLError('unknown url type: %s' % type)
urllib2.URLError: <urlopen error unknown url type: c>
The URLError that you mentioned was due to a bug in the perceptron.py file within the NLTK library for Windows.
In my machine, the file is at this location
C:\Python27\Lib\site-packages\nltk-3.2-py2.7.egg\nltk\tag\perceptron.py
(Basically look at an equivalent location within yours wherever you have the Python27 folder)
The bug was basically in the code to find the corresponding location for the averaged_perceptron_tagger within your machine. One can have a look at the line 801 and 924 mentioned in the data.py file regarding this.
I think the NLTK developer community recently fixed this bug in the code. Have a look at this commit made to their code a few days back.
https://github.com/nltk/nltk/commit/d3de14e58215beebdccc7b76c044109f6197d1d9#diff-26b258372e0d13c2543de8dbb1841252
The snippet where the change was made is as follows;
self.tagdict = {}
self.classes = set()
if load:
AP_MODEL_LOC = 'file:'+str(find('taggers/averaged_perceptron_tagger/'+PICKLE))
self.load(AP_MODEL_LOC)
# Initially it was:AP_MODEL_LOC = str(find('taggers/averaged_perceptron_tagger/'+PICKLE))
def tag(self, tokens):
Updating the file to the most recent commit worked for me and was able to use the nltk.pos_tag command. I believe this would resolve your problem as well (assuming you have everything else set up).
EDITED
This issue has been resolved from NLTK v3.2.1. Please upgrade your NLTK!
First read #MananVyas answer for the why:
https://stackoverflow.com/a/35902494/610569
Here's the how, without downgrading to NLTK v3.1, using NLTK 3.2, you can use this "hack":
>>> from nltk.tag import PerceptronTagger
>>> from nltk.data import find
>>> PICKLE = "averaged_perceptron_tagger.pickle"
>>> AP_MODEL_LOC = 'file:'+str(find('taggers/averaged_perceptron_tagger/'+PICKLE))
>>> tagger = PerceptronTagger(load=False)
>>> tagger.load(AP_MODEL_LOC)
>>> pos_tag = tagger.tag
>>> pos_tag('The quick brown fox jumps over the lazy dog'.split())
[('The', 'DT'), ('quick', 'JJ'), ('brown', 'NN'), ('fox', 'NN'), ('jumps', 'VBZ'), ('over', 'IN'), ('the', 'DT'), ('lazy', 'JJ'), ('dog', 'NN')]
I faced the same issue a while back.
Solution:
nltk.download('averaged_perceptron_tagger')

MySQL 5.5. installation on Windows doesn't show up in the registry properly

I am trying to get Django with MySQL working on my Windows 7 machine.
I need mySQLDB interface for this. When I try to install "mySQLDB interface", it looks for the MySQL installation in HKEY_LOCAL_MACHINE.
But in my registry it shows up in HKEY_CURRENT_USER/SOFTWARE/MySQL AB/MySQL Server 5.5.
My SQL instance seems to work fine.
MySQLDB installer somehow needs this in HKEY_LOCAL_MACHINE (I think) as it doesn't let me finish the install. It throws me this error.
Traceback (most recent call last):
File "setup.py", line 15, in <module>
metadata, options = get_config()
File "C:\Blah\Software\MySQL-python-1.2.3\setup_windows.
py", line 8, in get_config
mysql_root, dummy = _winreg.QueryValueEx(serverKey,'Location')
WindowsError: [Error 2] The system cannot find the file specified
Thanks a lot for your time.
You can fix the registry key in site.cfg. Or you can download a Windows MSI package from SourceForge. (No, it did not exist when the question was posted.)

Resources