Python :[Error 3] The system cannot find the path specified:
I am running this code from a file called archive and in archive there are more folders and in each of these folders, there are one or more text files. I want to make a list that includes the path to each of these folders. However the following error appears.
I currently have the python script where I wrote this code in the same folder as archive and it will trigger this error. What should I do in order to stop this error and get all the file paths.
I am pretty bad at using os and I don’t use it that often so I apologize if this is a trivial question.
So I have made some progress and now I corpus path is essentially a list with the path to all of the desired folders. Now all I am trying to do is get all of the paths to the text files inside these folders but I still run into issues and I don’t know how but error such as
1 Answer 1
You must be on windows machine. Error is because of os.listdir(). os.listdir() is not getting correct path.
And in line number 3, you are doing os.path.join(«archive», directories). You should join complete path including drive (C: or D:) like «c:/archive/foo: or on linux «home/root/archive/foo»
On Windows, the drive letter is not reset when an absolute path component (e.g., r’\foo’) is encountered. If a component contains a drive letter, all previous components are thrown away and the drive letter is reset. Note that since there is a current directory for each drive, os.path.join(«c:», «foo») represents a path relative to the current directory on drive C: (c:foo), not c:\foo.
Edit:
You are passing list corpus_path to [os.path.join][2] in line 6. That causes error! Replace corpus_path with items .
I created archive folder in my ‘D:’ Drive. Under archive folder I created 3 folders foo1, foo2 and foo3. Each folder contains 1 or 2 text file. Then I tested your code after modification. Code work fine. Here is the code:
‘python3’ is not recognized as an internal or external command, operable program or batch file
I am using Python 3.5.2 version on Windows 7 and tried using python3 app.py . I am getting this error message:
Is there any specific cause about why the python3 command is not working?
I also verified that the PATH is added to environment variables.
8 Answers 8
There is no python3.exe file, that is why it fails.
py is just a launcher for python.exe. If you have more than one python versions installed on your machine (2.x, 3.x) you can specify what version of python to launch by
Python3.exe is not defined in windows
Specify the path for required version of python when you need to used it by creating virtual environment for your project
Python 3
virtualenv —python=C:\PATH_TO_PYTHON\python.exe environment
Python2
virtualenv —python=C:\PATH_TO_PYTHON\python.exe environment
then activate the environment using
You can also try this: Go to the path where Python is installed in your system. For me it was something like C:\Users\\Local Settings\Application Data\Programs\Python\Python37 In this folder, you’ll find a python executable. Just create a duplicate and rename it to python3. Works every time.
If python2 is not installed on your computer, you can try with just python instead of python3
In my case I have a git hook on commit, specified by admin. So it was not very convenient for me to change the script (with python3 calls).
And the simplest workaround was just to copy python.exe to python3.exe.
Now I could launch both python and python3.
Enter the command to start up the server in that directory: py -3.7 -m http.server
Yes, I think for Windows users you need to change all the python3 calls to python to solve your original error. This change will run the Python version set in your current environment. If you need to keep this call as it is (aka python3 ) because you are working in cross-platform or for any other reason, then a work around is to create a soft link. To create it, go to the folder that contains the Python executable and create the link. For example, this worked in my case in Windows 10 using mklink:
Use a (soft) symbolic link in Linux:
Not the answer you’re looking for? Browse other questions tagged python-3.x python-3.5 or ask your own question.
Linked
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
site design / logo © 2020 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2020.10.21.37848
Microsoft Windows Python-3.6 PyCrypto installation error
pip install pycrypto works fine with python3.5.2 but fails wiht python3.6 with the following error:
inttypes.h(26): error C2061: syntax error: identifier ‘intmax_t’
8 Answers 8
The file include\pyport.h in Python installation directory does not have #include anymore. This leaves intmax_t undefined.
A workaround for Microsoft VC compiler is to force include stdint.h via OS environment variable CL:
- Open command prompt
- Setup VC environment by runing vcvars*.bat (choose file name depending on VC version and architecture)
- set CL=-FI»Full-Path\stdint.h» (use real value for Full-Path for the environment)
- pip install pycrypto
I’ve succeeded install pycrypto 2.6.1 on python 3.6, Windows 10, Visual Studio 2017.
Open «x86_x64 Cross-Tools Command Prompt for VS 2017» with administrator privilege in start menu.
pip install pycrypto
Thanks to user1960422’s answer.
PowerShell steps for pycrypto 2.6.1 (via simple-crypt) / Python 3.6 / Windows 10:
I also needed to follow the answer in: https://stackoverflow.com/a/24822876/8751739 to fix a winrandom module error.
Use PyCryptodome instead of pycrypto. pycrypto is discontinued and is no longer actively supported. PyCryptodome exposes almost the same API as pycrypto (source).
I’ve succeeded install pycrypo 2.6.1 on python 3.6 and windows 10.
- Set an environment variable like below.
- Open cmd.exe
- Activate virtualenv
- Download pycrypto 2.6.1 release from github and unzip it.
- set an environment variable for pycrypto set CL=/FI»%VCINSTALLDIR%\\INCLUDE\\stdint.h» %CL%
- Run setup command python setup.py install
- my result is here
I would be glad if this could be help someone.
Uninstall your current Python version
Install Python for amd64 architecture
Follow the other accepted solutions
-
- open «x86_x64 Cross-Tools Command Prompt for VS 2017»
-
- Add the new enviroment varible for your Visual Studio MSVC install path
-
- set CL=-FI»%VCINSTALLDIR%Tools\MSVC\14.11.25503\include\stdint.h»
-
- pip install pycrypto
For me this fixes it:
with Python 2, I have
with Python 3, I need
Installing python-dev python3-dev fixes it for me!
For ppl who is encountering same situation as mine:
- Windows 10 Enterprise v10.0.18363 Build 18363
- Python 3.8