I just installed Anaconda, but when I start Spyder it displays "An error occured while starting the kernel".
I tried updating everything, and unistalling/reinstalling Anaconda (inspired by what I have seen on other posts), but it doesn't work.
(It doesn't work either if I use the Jupiter or other programs).
Here is the full error message:
Traceback (most recent call last):
File "C:\Users\Quentin\Anaconda3\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Users\Quentin\Anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\Quentin\Anaconda3\lib\site‑packages\spyder_kernels\console\__main__.py", line 11, in
start.main()
File "C:\Users\Quentin\Anaconda3\lib\site‑packages\spyder_kernels\console\start.py", line 306, in main
kernel.initialize()
File "", line 2, in initialize
File "C:\Users\Quentin\Anaconda3\lib\site‑packages\traitlets\config\application.py", line 87, in catch_config_error
return method(app, *args, **kwargs)
File "C:\Users\Quentin\Anaconda3\lib\site‑packages\ipykernel\kernelapp.py", line 562, in initialize
self.init_kernel()
File "C:\Users\Quentin\Anaconda3\lib\site‑packages\ipykernel\kernelapp.py", line 447, in init_kernel
user_ns=self.user_ns,
File "C:\Users\Quentin\Anaconda3\lib\site‑packages\traitlets\config\configurable.py", line 412, in instance
inst = cls(*args, **kwargs)
File "C:\Users\Quentin\Anaconda3\lib\site‑packages\spyder_kernels\console\kernel.py", line 37, in __init__
super(SpyderKernel, self).__init__(*args, **kwargs)
File "C:\Users\Quentin\Anaconda3\lib\site‑packages\ipykernel\ipkernel.py", line 68, in __init__
kernel = self,
File "C:\Users\Quentin\Anaconda3\lib\site‑packages\traitlets\config\configurable.py", line 412, in instance
inst = cls(*args, **kwargs)
File "C:\Users\Quentin\Anaconda3\lib\site‑packages\IPython\core\interactiveshell.py", line 687, in __init__
self.init_magics()
File "C:\Users\Quentin\Anaconda3\lib\site‑packages\ipykernel\zmqshell.py", line 593, in init_magics
super(ZMQInteractiveShell, self).init_magics()
File "C:\Users\Quentin\Anaconda3\lib\site‑packages\IPython\core\interactiveshell.py", line 2250, in init_magics
m.PylabMagics, m.ScriptMagics,
File "C:\Users\Quentin\Anaconda3\lib\site‑packages\IPython\core\magic.py", line 405, in register
m = m(shell=self.shell)
File "C:\Users\Quentin\Anaconda3\lib\site‑packages\IPython\core\magics\osm.py", line 52, in __init__
self.execre = re.compile(r'(.*)\.(%s)$' % winext,re.IGNORECASE)
File "C:\Users\Quentin\Anaconda3\lib\re.py", line 234, in compile
return _compile(pattern, flags)
File "C:\Users\Quentin\Anaconda3\lib\re.py", line 286, in _compile
p = sre_compile.compile(pattern, flags)
File "C:\Users\Quentin\Anaconda3\lib\sre_compile.py", line 764, in compile
p = sre_parse.parse(p, flags)
File "C:\Users\Quentin\Anaconda3\lib\sre_parse.py", line 924, in parse
p = _parse_sub(source, pattern, flags & SRE_FLAG_VERBOSE, 0)
File "C:\Users\Quentin\Anaconda3\lib\sre_parse.py", line 420, in _parse_sub
not nested and not items))
File "C:\Users\Quentin\Anaconda3\lib\sre_parse.py", line 810, in _parse
p = _parse_sub(source, state, sub_verbose, nested + 1)
File "C:\Users\Quentin\Anaconda3\lib\sre_parse.py", line 420, in _parse_sub
not nested and not items))
File "C:\Users\Quentin\Anaconda3\lib\sre_parse.py", line 501, in _parse
code = _escape(source, this, state)
File "C:\Users\Quentin\Anaconda3\lib\sre_parse.py", line 402, in _escape
raise source.error("bad escape %s" % escape, len(escape))
re.error: bad escape \M at position 52
I would be very grateful if someone would help me.
So I met someone who was good at this and he solved my problem.
He somehow figured out that there was a problem with my environnement variables.
In the environnement variables, in the system variable PATHEXT, are stored some extensions (.COM, .EXE, .CMD,...) that can be recognized by the system. I had an alien in mine, which was not an extension (in that case, it was "C:/HOME/MinGW").
I deleted it and it worked.
This can be set via Window's configuration pannel -> modify system environnement variable. Then press on "environnement variables". On the "system variable" list, select "PATHEXT" and press "modify...".
(NB: My Windows is in French so the names are translated by myself and may not perfectly match to other languages'Windows)
Related
When trying to create a fabric2.Connection, Paramiko tries to invoke a local /bin/bash command:
$ fab2 db-shell
Traceback (most recent call last):
File "/nix/store/m2iyj18cifr4a1rvpfgphg7kfgsf2pj2-python3.9-fabric2-2.7.1/bin/.fab2-wrapped", line 9, in <module>
sys.exit(program.run())
File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/invoke/program.py", line 384, in run
self.execute()
File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/invoke/program.py", line 566, in execute
executor.execute(*self.tasks)
File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/invoke/executor.py", line 129, in execute
result = call.task(*args, **call.kwargs)
File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/invoke/tasks.py", line 127, in __call__
result = self.body(*args, **kwargs)
File "/home/username/project/fabfile.py", line 645, in db_shell
bastion_connection().run(
File "/home/username/project/fabfile_utils.py", line 141, in bastion_connection
conn = Connection(
File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/fabric2/connection.py", line 403, in __init__
self.ssh_config = self.config.base_ssh_config.lookup(host)
File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/paramiko/config.py", line 223, in lookup
options = self._lookup(hostname=hostname)
File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/paramiko/config.py", line 250, in _lookup
or self._does_match(
File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/paramiko/config.py", line 389, in _does_match
passed = invoke.run(exec_cmd, hide="stdout", warn=True).ok
File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/invoke/__init__.py", line 48, in run
return Context().run(command, **kwargs)
File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/invoke/context.py", line 95, in run
return self._run(runner, command, **kwargs)
File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/invoke/context.py", line 102, in _run
return runner.run(command, **kwargs)
File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/invoke/runners.py", line 380, in run
return self._run_body(command, **kwargs)
File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/invoke/runners.py", line 431, in _run_body
self.start(command, self.opts["shell"], self.env)
File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/invoke/runners.py", line 1291, in start
self.process = Popen(
File "/nix/store/0zzvjh5gnz0ny7ckilzyn9hmg5lypszf-python3-3.9.13/lib/python3.9/subprocess.py", line 951, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/nix/store/0zzvjh5gnz0ny7ckilzyn9hmg5lypszf-python3-3.9.13/lib/python3.9/subprocess.py", line 1821, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/bin/bash'
I've not been able to find anything in the docs about this yet.
I'm running fabric2==2.7.1, invoke==1.6.0, and paramiko==2.8.0 on NixOS stable 22.11.
Invoke currently defaults to /bin/bash, which is a known issue, since operating systems like Alpine and NixOS don't have that path. Fortunately we can specify a command in $PATH rather than manually looking it up, so adding the following to the Connection call does the trick: config=invoke.Config(overrides={"shell": "bash"}).
I am trying to make an executable of a python 3.10 file using PyInstaller in the command prompt:
python -m PyInstaller --onefile 1.0.py
with "1.0" being my file name. I have done this many times before on the same PC and with the same python version, but for this file it is throwing a "file specified not found" error:
while run_next_command(read_fh, write_fh):
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1776.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1776.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:\Users\jackp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\PyInstaller\__main__.py", line 188, in <module>
run()
File "C:\Users\jackp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\PyInstaller\__main__.py", line 178, in run
run_build(pyi_config, spec_file, **vars(args))
File "C:\Users\jackp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\PyInstaller\__main__.py", line 59, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "C:\Users\jackp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\PyInstaller\building\build_main.py", line 934, in main
build(specfile, distpath, workpath, clean_build)
File "C:\Users\jackp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\PyInstaller\building\build_main.py", line 856, in build
exec(code, spec_namespace)
File "E:\Python Scripts\High Spen\Combined\1.0.spec", line 7, in <module>
a = Analysis(
File "C:\Users\jackp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\PyInstaller\building\build_main.py", line 381, in __init__
self.__postinit__()
File "C:\Users\jackp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\PyInstaller\building\datastruct.py", line 173, in __postinit__
self.assemble()
File "C:\Users\jackp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\PyInstaller\building\build_main.py", line 660, in assemble
isolated.call(find_binary_dependencies, list(self.binaries), self.binding_redirects, collected_packages)
File "C:\Users\jackp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\PyInstaller\isolated\_parent.py", line 238, in call
return isolated.call(function, *args, **kwargs)
File "C:\Users\jackp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\PyInstaller\isolated\_parent.py", line 176, in call
raise RuntimeError(f"Child process call to {function.__name__}() failed with:\n" + output)
RuntimeError: Child process call to find_binary_dependencies() failed with:
File "C:\Users\jackp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\win32ctypes\pywin32\pywintypes.py", line 35, in pywin32error
yield
File "C:\Users\jackp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\win32ctypes\pywin32\win32api.py", line 43, in LoadLibraryEx
return _dll._LoadLibraryEx(fileName, 0, flags)
File "C:\Users\jackp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\win32ctypes\core\cffi\_dll.py", line 23, in _LoadLibraryEx
result = check_null(
File "C:\Users\jackp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\win32ctypes\core\cffi\_util.py", line 81, in __call__
self._raise_error(function_name)
File "C:\Users\jackp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\win32ctypes\core\cffi\_util.py", line 92, in _raise_error
raise exception
OSError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\jackp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\PyInstaller\isolated\_child.py", line 63, in run_next_command
output = function(*args, **kwargs)
File "C:\Users\jackp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\PyInstaller\building\build_main.py", line 162, in find_binary_dependencies
return bindepend.Dependencies(binaries, redirects=binding_redirects, xtrapath=extra_libdirs)
File "C:\Users\jackp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\PyInstaller\depend\bindepend.py", line 205, in Dependencies
for ftocnm, fn in getAssemblyFiles(pth, manifest, redirects):
File "C:\Users\jackp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\PyInstaller\depend\bindepend.py", line 372, in getAssemblyFiles
for assembly in getAssemblies(pth):
File "C:\Users\jackp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\PyInstaller\depend\bindepend.py", line 326, in getAssemblies
res = winmanifest.GetManifestResources(pth)
File "C:\Users\jackp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\PyInstaller\utils\win32\winmanifest.py", line 979, in GetManifestResources
return winresource.GetResources(filename, [RT_MANIFEST], names, languages)
File "C:\Users\jackp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\PyInstaller\utils\win32\winresource.py", line 155, in GetResources
hsrc = win32api.LoadLibraryEx(filename, 0, LOAD_LIBRARY_AS_DATAFILE)
File "C:\Users\jackp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\win32ctypes\pywin32\win32api.py", line 42, in LoadLibraryEx
with _pywin32error():
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1776.0_x64__qbz5n2kfra8p0\lib\contextlib.py", line 153, in __exit__
self.gen.throw(typ, value, traceback)
File "C:\Users\jackp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\win32ctypes\pywin32\pywintypes.py", line 37, in pywin32error
raise error(exception.winerror, exception.function, exception.strerror)
win32ctypes.pywin32.pywintypes.error: (2, 'LoadLibraryEx', 'The system cannot find the file specified')
Please could someone let me know how I would solve this or otherwise another method of turning this into an .exe. Thanks
Update:
I have tried uninstalling my python 3.10 and downloading 3.7 instead, as I saw somewhere that PyInstaller is incompatible with 3.8 and above, but this still didn't work for another reason. So I reinstalled 3.10 (effectively at this point I have uninstalled and reinstalled my python and IDE) and I am still getting the same error.
I am executing the command flask migrate to create the referring tables more at the moment it starts to run, even though it identifies the tables, it throws the following error. I usually look for and find errors easily, but on this occasion I cannot identify it easily.
PDT: I am new to the subject of programming thanks for the understanding and time.
Mainly what I need is to know where the error is to be able to correct it but the extensions that it calls here do not refer to anything that I have written., Thanks
INFO [alembic.autogenerate.compare] Detected added column 'blog_user.youtube'
Traceback (most recent call last):
File "c:\users\user\appdata\local\programs\python\python38-32\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\users\user\appdata\local\programs\python\python38-32\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\user\Desktop\LLAC\env\Scripts\flask.exe\__main__.py", line 7, in <module>
File "c:\users\user\desktop\llac\env\lib\site-packages\flask\cli.py", line 967, in main
cli.main(args=sys.argv[1:], prog_name="python -m flask" if as_module else None)
File "c:\users\user\desktop\llac\env\lib\site-packages\flask\cli.py", line 586, in main
return super(FlaskGroup, self).main(*args, **kwargs)
File "c:\users\user\desktop\llac\env\lib\site-packages\click\core.py", line 782, in main
rv = self.invoke(ctx)
File "c:\users\user\desktop\llac\env\lib\site-packages\click\core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "c:\users\user\desktop\llac\env\lib\site-packages\click\core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "c:\users\user\desktop\llac\env\lib\site-packages\click\core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "c:\users\user\desktop\llac\env\lib\site-packages\click\core.py", line 610, in invoke
return callback(*args, **kwargs)
File "c:\users\user\desktop\llac\env\lib\site-packages\click\decorators.py", line 21, in new_func
return f(get_current_context(), *args, **kwargs)
File "c:\users\user\desktop\llac\env\lib\site-packages\flask\cli.py", line 426, in decorator
return __ctx.invoke(f, *args, **kwargs)
File "c:\users\user\desktop\llac\env\lib\site-packages\click\core.py", line 610, in invoke
return callback(*args, **kwargs)
File "c:\users\user\desktop\llac\env\lib\site-packages\flask_migrate\cli.py", line 89, in migrate
_migrate(directory, message, sql, head, splice, branch_label, version_path,
File "c:\users\user\desktop\llac\env\lib\site-packages\flask_migrate\__init__.py", line 96, in wrapped
f(*args, **kwargs)
File "c:\users\user\desktop\llac\env\lib\site-packages\flask_migrate\__init__.py", line 210, in migrate
command.revision(config, message, autogenerate=True, sql=sql,
File "c:\users\user\desktop\llac\env\lib\site-packages\alembic\command.py", line 221, in revision
scripts = [script for script in revision_context.generate_scripts()]
File "c:\users\user\desktop\llac\env\lib\site-packages\alembic\command.py", line 221, in <listcomp>
scripts = [script for script in revision_context.generate_scripts()]
File "c:\users\user\desktop\llac\env\lib\site-packages\alembic\autogenerate\api.py", line 513, in generate_scripts
yield self._to_script(generated_revision)
File "c:\users\user\desktop\llac\env\lib\site-packages\alembic\autogenerate\api.py", line 425, in _to_script
render._render_python_into_templatevars(
File "c:\users\user\desktop\llac\env\lib\site-packages\alembic\autogenerate\render.py", line 49, in _render_python_into_templatevars
_render_cmd_body(upgrade_ops, autogen_context)
File "c:\users\user\desktop\llac\env\lib\site-packages\alembic\autogenerate\render.py", line 71, in _render_cmd_body
lines = render_op(autogen_context, op)
File "c:\users\user\desktop\llac\env\lib\site-packages\alembic\autogenerate\render.py", line 87, in render_op
lines = util.to_list(renderer(autogen_context, op))
File "c:\users\user\desktop\llac\env\lib\site-packages\alembic\autogenerate\render.py", line 179, in _add_table
for rcons in [
File "c:\users\user\desktop\llac\env\lib\site-packages\alembic\autogenerate\render.py", line 180, in <listcomp>
_render_constraint(cons, autogen_context)
File "c:\users\user\desktop\llac\env\lib\site-packages\alembic\autogenerate\render.py", line 775, in _render_constraint
return renderer(constraint, autogen_context)
File "c:\users\user\desktop\llac\env\lib\site-packages\alembic\autogenerate\render.py", line 871, in _render_foreign_key
"refcols": ", ".join(
File "c:\users\user\desktop\llac\env\lib\site-packages\alembic\autogenerate\render.py", line 872, in <genexpr>
repr(_fk_colspec(f, apply_metadata_schema))
File "c:\users\user\desktop\llac\env\lib\site-packages\alembic\autogenerate\render.py", line 808, in _fk_colspec
tname, colname = tokens[-2:]
ValueError: not enough values to unpack (expected 2, got 1)
I am running into the same error. In my case the error disappears if I remove the table_args . Then the migration works so I think it has probably to do with the ForeignKey constraints.
class AccommodationAirport(db.Model):
__tablename__ = 'accommodation_airport'
__table_args__ = (
ForeignKeyConstraint(
['supplier'], ['accommodation'],
name='fk_acco_airp_sup_acco'
),
UniqueConstraint(
'supplier', 'accommodation', 'airport',
name='uq_sup_acco_airp'
)
)
created = db.Column(db.DateTime, server_default=func.now())
last_modified = db.Column(db.DateTime, onupdate=func.now())
modified_by = db.Column(db.Integer)
supplier = db.Column(db.String(8), primary_key=True)
accommodation = db.Column(db.String(32), primary_key=True)
airport = db.Column(db.String(3), primary_key=True)
The only solution I have found so far is to
comment out the table_args with the Constraint declarations,
migrate -> upgrade
uncomment the table_args
migrate -> upgrade
I am currently working on test automation using Python. I was trying to use Allure which, first, requires Pytest. After installing these two module, I proceeded to call:
pytest --alluredir $OutputPath
But got the [WinError 87] parameter not found message. In order to confirm that Allure was not causing the problem I then tried to only invoke Pytest through the Python interpreter from the command line with:
python -m pytest
But still got the same error. Looking online, this error has been happening for a while but I cannot seem to find an answer.
I'm using these versions:
Python-> 3.7.4
Pytest-> 5.2.1
IDE-----> Visual Studio code
OS-----> Windows 7
Full Traceback:
Traceback (most recent call last):
File "c:\users\c.hernandezperez\appdata\local\continuum\anaconda3\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\users\c.hernandezperez\appdata\local\continuum\anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\c.hernandezperez\AppData\Local\Continuum\anaconda3\Scripts\pytest.exe\__main__.py", line 9, in <module>
File "c:\users\c.hernandezperez\appdata\local\continuum\anaconda3\lib\site-packages\_pytest\config.py", line 54, in main
config = _prepareconfig(args, plugins)
File "c:\users\c.hernandezperez\appdata\local\continuum\anaconda3\lib\site-packages\_pytest\config.py", line 167, in _prepareconfig
pluginmanager=pluginmanager, args=args
File "c:\users\c.hernandezperez\appdata\local\continuum\anaconda3\lib\site-packages\pluggy\__init__.py", line 617, in __call__
return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
File "c:\users\c.hernandezperez\appdata\local\continuum\anaconda3\lib\site-packages\pluggy\__init__.py", line 222, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "c:\users\c.hernandezperez\appdata\local\continuum\anaconda3\lib\site-packages\pluggy\__init__.py", line 216, in <lambda>
firstresult=hook.spec_opts.get('firstresult'),
File "c:\users\c.hernandezperez\appdata\local\continuum\anaconda3\lib\site-packages\pluggy\callers.py", line 196, in _multicall
gen.send(outcome)
File "c:\users\c.hernandezperez\appdata\local\continuum\anaconda3\lib\site-packages\_pytest\helpconfig.py", line 89, in pytest_cmdline_parse
config = outcome.get_result()
File "c:\users\c.hernandezperez\appdata\local\continuum\anaconda3\lib\site-packages\pluggy\callers.py", line 76, in get_result
raise ex[1].with_traceback(ex[2])
File "c:\users\c.hernandezperez\appdata\local\continuum\anaconda3\lib\site-packages\pluggy\callers.py", line 180, in _multicall
res = hook_impl.function(*args)
File "c:\users\c.hernandezperez\appdata\local\continuum\anaconda3\lib\site-packages\_pytest\config.py", line 981, in pytest_cmdline_parse
self.parse(args)
File "c:\users\c.hernandezperez\appdata\local\continuum\anaconda3\lib\site-packages\_pytest\config.py", line 1146, in parse
self._preparse(args, addopts=addopts)
File "c:\users\c.hernandezperez\appdata\local\continuum\anaconda3\lib\site-packages\_pytest\config.py", line 1108, in _preparse
early_config=self, args=args, parser=self._parser
File "c:\users\c.hernandezperez\appdata\local\continuum\anaconda3\lib\site-packages\pluggy\__init__.py", line 617, in __call__
return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
File "c:\users\c.hernandezperez\appdata\local\continuum\anaconda3\lib\site-packages\pluggy\__init__.py", line 222, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "c:\users\c.hernandezperez\appdata\local\continuum\anaconda3\lib\site-packages\pluggy\__init__.py", line 216, in <lambda>
firstresult=hook.spec_opts.get('firstresult'),
File "c:\users\c.hernandezperez\appdata\local\continuum\anaconda3\lib\site-packages\pluggy\callers.py", line 201, in _multicall
return outcome.get_result()
File "c:\users\c.hernandezperez\appdata\local\continuum\anaconda3\lib\site-packages\pluggy\callers.py", line 76, in get_result
raise ex[1].with_traceback(ex[2])
File "c:\users\c.hernandezperez\appdata\local\continuum\anaconda3\lib\site-packages\pluggy\callers.py", line 175, in _multicall
next(gen) # first yield
File "c:\users\c.hernandezperez\appdata\local\continuum\anaconda3\lib\site-packages\_pytest\capture.py", line 46, in pytest_load_initial_conftests
_py36_windowsconsoleio_workaround(sys.stdout)
File "c:\users\c.hernandezperez\appdata\local\continuum\anaconda3\lib\site-packages\_pytest\capture.py", line 711, in _py36_windowsconsoleio_workaround
sys.__stdin__ = sys.stdin = _reopen_stdio(sys.stdin, "rb")
File "c:\users\c.hernandezperez\appdata\local\continuum\anaconda3\lib\site-packages\_pytest\capture.py", line 704, in _reopen_stdio
open(os.dup(f.fileno()), mode, buffering),
OSError: [WinError 87] El parámetro no es correcto
Apparently Python 3.7.4 does not work with Pytest as stated on this GitHub question. This question is thus considered answered.
I have a file global_vars.py that contains file paths saved as variables:
from pandas import Timestamp
final_vol_path = 'datasets/final_vols.csv'
final_price_path = 'datasets/final_prices.csv'
final_start_date = Timestamp('2017-01-01')
with other variables written in a similar fashion. However, the functions that I'm using to read in the data throw a FileNotFoundError when attempting to do the following in file1.py:
import scripts.global_vars as gv
read_data(gv.final_vol_path, gv.final_price_path) # throws FileNotFoundError
read_data('datasets/final_vols.csv', 'datasets/final_prices.csv') # this passes
Additionally, I've checked the file paths, and have gotten the following:
gv.final_vol_path == 'datasets/final_vols.csv' # returns True
gv.final_price_path == 'datasets/final_prices.csv' # returns True
Moreover, the pandas Timestamp object is processed without any problems.
Is there any explanation for why the FileNotFoundError is being thrown when attempting to access the file path as a variable from global_vars.py, but is not thrown when the actual string is passed in?
EDIT: The overall directory structure is as follows:
working_dir
L file1.py
L scripts
L global_vars.py
L datasets
L final_vols.csv
L final_prices.csv
EDIT 2: I added in a try-catch block to ensure the rest of the function doesn't break, not sure if that has affected the traceback, but here's what I get:
Traceback (most recent call last):
File "c:\users\ananth\anaconda3\envs\analytics-cpu\lib\runpy.py", line
184, in _run_module_as_main
"__main__", mod_spec)
File "c:\users\ananth\anaconda3\envs\analytics-cpu\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\Ananth\Anaconda3\envs\analytics-cpu\Scripts\nose2.exe\__main__.py", line 9, in <module>
File "c:\users\ananth\anaconda3\envs\analytics-cpu\lib\site-packages\nose2\main.py", line 306, in discover
return main(*args, **kwargs)
File "c:\users\ananth\anaconda3\envs\analytics-cpu\lib\site-packages\nose2\main.py", line 100, in __init__
super(PluggableTestProgram, self).__init__(**kw)
File "c:\users\ananth\anaconda3\envs\analytics-cpu\lib\unittest\main.py", line 93, in __init__
self.parseArgs(argv)
File "c:\users\ananth\anaconda3\envs\analytics-cpu\lib\site-packages\nose2\main.py", line 133, in parseArgs
self.createTests()
File "c:\users\ananth\anaconda3\envs\analytics-cpu\lib\site-packages\nose2\main.py", line 258, in createTests
self.testNames, self.module)
File "c:\users\ananth\anaconda3\envs\analytics-cpu\lib\site-packages\nose2\loader.py", line 69, in loadTestsFromNames
for name in event.names]
File "c:\users\ananth\anaconda3\envs\analytics-cpu\lib\site-packages\nose2\loader.py", line 69, in <listcomp>
for name in event.names]
File "c:\users\ananth\anaconda3\envs\analytics-cpu\lib\site-packages\nose2\loader.py", line 84, in loadTestsFromName
result = self.session.hooks.loadTestsFromName(event)
File "c:\users\ananth\anaconda3\envs\analytics-cpu\lib\site-packages\nose2\events.py", line 224, in __call__
result = getattr(plugin, self.method)(event)
File "c:\users\ananth\anaconda3\envs\analytics-cpu\lib\site-packages\nose2\plugins\loader\testcases.py", line 56, in loadTestsFromName
result = util.test_from_name(name, module)
File "c:\users\ananth\anaconda3\envs\analytics-cpu\lib\site-packages\nose2\util.py", line 106, in test_from_name
parent, obj = object_from_name(name, module)
File "c:\users\ananth\anaconda3\envs\analytics-cpu\lib\site-packages\nose2\util.py", line 117, in object_from_name
module = __import__('.'.join(parts_copy))
File "C:\Users\Ananth\Desktop\Modules\PortfolioVARModule\tests\test_simulation.py", line 24, in <module>
gv.test_start_date)
File "C:\Users\Ananth\Desktop\Modules\PortfolioVARModule\scripts\prep_data.py", line 119, in read_data
priceDF = pd.read_csv(pricepath).dropna()
File "c:\users\ananth\anaconda3\envs\analytics-cpu\lib\site-packages\pandas\io\parsers.py", line 646, in parser_f
return _read(filepath_or_buffer, kwds)
File "c:\users\ananth\anaconda3\envs\analytics-cpu\lib\site-packages\pandas\io\parsers.py", line 389, in _read
parser = TextFileReader(filepath_or_buffer, **kwds)
File "c:\users\ananth\anaconda3\envs\analytics-cpu\lib\site-packages\pandas\io\parsers.py", line 730, in __init__
self._make_engine(self.engine)
File "c:\users\ananth\anaconda3\envs\analytics-cpu\lib\site-packages\pandas\io\parsers.py", line 923, in _make_engine
self._engine = CParserWrapper(self.f, **self.options)
File "c:\users\ananth\anaconda3\envs\analytics-cpu\lib\site-packages\pandas\io\parsers.py", line 1390, in __init__
self._reader = _parser.TextReader(src, **kwds)
File "pandas\parser.pyx", line 373, in pandas.parser.TextReader.__cinit__ (pandas\parser.c:4184)
File "pandas\parser.pyx", line 667, in pandas.parser.TextReader._setup_parser_source (pandas\parser.c:8449)
FileNotFoundError: File b'datasets/corn_price.csv' does not exist
Problem is the addition of the letter b in front of your file's path.
You get the b because you encoded to utf-8.
Try:
read_data(str(gv.final_vol_path,'utf-8'), str(gv.final_price_path, 'utf-8'))