Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot getting the Current directory Path in Python (Linux)
    primarykey
    data
    text
    <p>I was trying to execute the Program that I coded in Windows, in a Linux environment, I was consistently getting error on the line that was supposed to Import the file from the sub-folder.</p> <p>The program gives the following error,</p> <pre><code>Traceback (most recent call last): File "BlackBox.py", line 26, in &lt;module&gt; from BB_Files import BB_Expand ImportError: No module named BB_Files </code></pre> <p>Despite the presence of the file BB_Expand inside BB_Files folder, I am still getting the error.</p> <p>I have also tried appending the path of my current directories in Python,</p> <pre><code>sys.path.append("/home/pe/Desktop/AES") # Sub-Folders of AES are also accessible sys.path.append("/home/pe/Desktop/AES/BB_Files") </code></pre> <p>But Still no Luck,</p> <p>This is the File Structure,</p> <pre><code>/home/pe/Desktop/AES/Main.py /home/pe/Desktop/AES/BB_Files /home/pe/Desktop/AES/BB_Files/BB_Days.py /home/pe/Desktop/AES/BB_Files/BB_Expand.py /home/pe/Desktop/AES/BB_Files/BB_Steps.py </code></pre> <p>this is the output of <code>ls -l</code> command,</p> <pre><code>drwxrwx--x 4 pe users 4096 Oct 26 21:43 BB_Files -rw-rw---- 1 pe users 15284 Oct 26 22:04 Main.py </code></pre> <p>This is some initial code in the file,</p> <pre><code>import sys # sys.argv ; sys.path, sys.exit import os import hashlib import struct # Interpret strings as packed binary data import getopt # for Runtime arguments import time from datetime import date # Append Paths from where the Files would be Imported. sys.path.append("/home/pe/Desktop/AES") # Sub-Folders of AES are also accessible sys.path.append("/home/pe/Desktop/AES/BB_Files") # Sub-Fodlers of BB_Files are also accessible now (Tables) from BB_Files import BB_Expand from BB_Files import BB_Steps from BB_Files import BB_Days </code></pre> <p>This is the line giving an error,</p> <pre><code>from BB_Files import BB_Expand </code></pre> <p>The program doesn't run after this line because the Python couldn't find this Module.</p> <p>But when I tried to print the path of the current directory I get nothing, have a look,</p> <pre><code>print("Path is:",os.path.dirname(__file__)) print("sufiyan") </code></pre> <p><strong>Output:</strong></p> <pre><code>('Path is:', '') sufiyan Traceback (most recent call last): File "BlackBox.py", line 25, in &lt;module&gt; from bbfiles import bbexpand ImportError: No module named bbfiles </code></pre> <p>I want to know why the path is not being printed while its printing fine in Windows. All i get is a black space instead of the path of the current directory.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload