Python3 No Such File or Directory

Python3 no such file or directory

You don't have to put your python codes in a global path. Just make your python 3.4 interpreter interpreter available globally. For that, edit .bash_profile or .bashrc file in your home directory and add the following line:

export PATH=${PATH}:/usr/bin/python3

That will make python3 executable irrespective of your current working directory.
In order to execute code from your codes directory, you just have to write:

$ python3 ./your_code.py

Another way is to add the shebang at the top of your code as

#/usr/bin/python3

and change the permission to executable by the current user (by default it will not have execute permission).

$ chmod 744 your_code.py

and then executing the script directly as

$ your_code.py

I hope I could address your problem.

open() gives FileNotFoundError/IOError: Errno 2 No such file or directory

  • Make sure the file exists: use os.listdir() to see the list of files in the current working directory
  • Make sure you're in the directory you think you're in with os.getcwd() (if you launch your code from an IDE, you may well be in a different directory)
  • You can then either:
    • Call os.chdir(dir), dir being the folder where the file is
      located, then open the file with just its name like you were doing.
    • Specify an absolute path to the file in your open call.
  • Remember to use a raw string if your path uses backslashes, like
    so: dir = r'C:\Python32'
    • If you don't use raw-string, you have to escape every backslash: 'C:\\User\\Bob\\...'
    • Forward-slashes also work on Windows 'C:/Python32' and do not need to be escaped.

Let me clarify how Python finds files:

  • An absolute path is a path that starts with your computer's root directory, for example C:\Python\scripts if you're on Windows.
  • A relative path is a path that does not start with your computer's root directory, and is instead relative to something called the working directory. You can view Python's current working directory by calling os.getcwd().

If you try to do open('sortedLists.yaml'), Python will see that you are passing it a relative path, so it will search for the file inside the current working directory.

Calling os.chdir() will change the current working directory.

Example: Let's say file.txt is found in C:\Folder.

To open it, you can do:

os.chdir(r'C:\Folder')
open('file.txt') # relative path, looks inside the current working directory

or

open(r'C:\Folder\file.txt') # absolute path

Python 3.10 [Errono 2] No such file or directory - Python 3.10 not being recognised in terminal

The problem is with the command you've entered. This makes the Python interpreter think you're trying to run a script called v, which obviously doesn't exist.

python3 -- v

For checking the version, you should either:

  1. Use one hyphen and a capital letter: python -V
  2. Use two hyphens and the full word: python --version.

There should be no space after the hyphen.

Reading csv file keeping giving error No such file or directory

Pyscript is rapidly evolving. For now ...

You'll note for example py-config has replaced py-env, see here.

paths, that had been highlighted in section about local file access here, is now used differently. paths is now a list to specify local Python modules for installation, see here. open_url seems the suggested way to get items, see here and current pyscript demo example in action here.

If you are serving your HTML file from the same folder where your .csv file is (which I gather is the case from "I have literally put the csv file in the same folder as my html file"), then you can use relative URLs to point to it.

For example, hosting on GitHub along side the .csv file works in this example below at present:

<html>
<head>
<title>Panndas Example with reading from relative url in the same location where HTML resides</title>
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
</head>
<py-config>
packages = [
"pandas",
"jinja2"
]
</py-config>
<body>
<h1>Hello World!</h1>
<p>This is a test To see how my html code is.</p>
<p>This space below will become blank as a few seconds is taken to render the dataframe. Be patient ...</p>
<div id="pane"></div>

<py-script>
import pandas as pd

from pyodide.http import open_url

url = 'penguins.csv'
df = pd.read_csv(open_url(url))

df.head(39).style.format(precision=2)

</py-script>

</body>

</html>

You can see the HTML running here.

Note that it may break a few hours or days from now. As this older route similar to OP's approach is now outdated.


If you aren't trying to just display the Pandas dataframe... Alternatively, if you want to use Pyodide/WASM to work with data from .csv actively, you can use the file browser in JupyterLite to place your local .csv into the virtual system and interactively use the data contained in it with Pandas. See my suggestion here. If you make any useful changes, be sure to save the new data and download the modified version back out of the virtual file system inside your browser, to your local machine's file handling system. Otherwise, you take chances that a change to your browser or clearing the cache could wipe what you coded or made from the internal storage.

bad interpreter: /usr/bin/python3: no such file or directory on Kali Linux

You can create a symbolic link pointing your /usr/bin/python to /usr/bin/python3.

ln -s /usr/bin/python /usr/bin/python3



Related Topics



Leave a reply



Submit