Python_d.exe and venv -- can't find "python_d.exe" - python

I'm using PyCharm and trying to set up a Flask project with a virtual environment. Whenever I select to do "New environment using Virtualenv" the base interpreter location seems to be right yet I continually get the error that there is no such file or directory "\python_d.exe" I don't think this is just a PyCharm error as I also get the same error when trying to do it from the terminal. I'm not quite sure why it's looking for python_d.exe instead of python.exe
I've already edited my PATH variable to be where my python executable is stored. And while installing Python (at the recommendation of other questions on this forum), selected to add to the PATH variable and also install for all users. I'm not sure where else to go on this, so any help is appreciated.
This is the error I get when I run the below command on the terminal.
> python -m venv C:\<path to where I want it to go>\venv
Error: [Errno 2] No such file or directory: 'C:\\<my specific path>\Python\\Python37-32\\lib\\venv\\scripts\\nt\\python_d.exe'

In the installation program of python seek if you have installed the debug file binaries.
python_d.exe is a file installed with that option activated.

Related

How to move a Python Interpreter directory without reinstall or creating a virtual environment on Windows?

I want to move my python interpreter from D:\Softwares\Python to D:\Softwares\Python\Python3.7 which was originally installed in the first directory without reinstalling or creating a virtual environment on Windows.
I just simply created a new folder Python3.7 and moved the files. Then I updated the PYTHONPATH environment variable.
If I run python -v in cmd, I can correctly see the version. But when I run scrapy shell [url], there's an error:
Fatal error in launcher: Unable to create process using '"d:\softwares\python\python.exe" "D:\Softwares\Python\Python3.7\Scripts\scrapy.exe" shell http://guba.eastmoney.com/list,cjpl.html': ???????????
I know there's something wrong with my python.exe path, but I don't know how to fix it without reinstalling the interpreter.
I'd appreciate it a lot for your help.
note: I've already changed the environment variable path.
I find the solution. Just reinstalling scrapy works.

Module not found error in VS code despite the fact that I installed it

I'm trying to debug some python code using VS code. I'm getting the following error about a module that I am sure is installed.
Exception has occurred: ModuleNotFoundError
No module named 'SimpleITK'
File "C:\Users\Mido\Desktop\ProstateX-project\src\01-preprocessing\03_resample_nifti.py", line 8, in <module>
import SimpleITK as sitk
I installed the module using
sudo pip install SimpleITK
I know that it was installed because I was getting a similar error when I ran the code through the command line, and it was fixed by doing the above. I don't understand why VS code does not recognize that
After installing a new module via pip reloading vscode may work if vscode doesn't recognize it. To do this, make sure that the module is installed inside the virtual environment by creating and activating a virtualenv:
python3 -m venv env
source env/bin/activate
Make sure to use the correct way of installing a module with pip:
python3 -m pip install {new_module}
Replace the string "{new_module}" with your module name. After that, make sure to reload vscode by clicking Ctrl+Shift+P, and selecting Reload window.
Now vscode will know the new module and autocompletion works.
sudo pip install is most likely installing globally into a Python interpreter that is different than the one that you have selected in VS Code. Please select the Python interpreter you want to use and then install explicitly using that interpreter (if you're not using a virtual environment then use something like /path/to/python -m pip install SimpleITK, although I strongly recommend using a virtual environment and to not install packages globally).
In Mac, correctly selecting the Python Interpreter worked for me:
From within VS Code, select a Python 3 interpreter by opening the Command Palette (⇧⌘P), start typing the Python: Select Interpreter command to search, then select the command. You can also use the Select Python Environment option on the Status Bar if available (it may already show a selected interpreter, too):
No interpreter selected
The command presents a list of available interpreters that VS Code can find automatically, including virtual environments. If you don't see the desired interpreter, see Configuring Python environments.
Source :VS Code Select Interpreter
This error: your vscode use other python version. This solution change vscode use current python.
In terminal find current python version:
py --version
In vscode Press Ctrl+Shift+P then type:
Python: Select Interpreter
Select current python version
I ran into this problem with VSCode and resolved it by setting my Python interpreter within VSCode to the same as the one in my system path (type "echo %PATH%" on Windows and look for Python) via the process here: https://code.visualstudio.com/docs/python/python-tutorial#_select-a-python-interpreter
There are a lot of proposed answers that suggest changing the launch.json or the settings.json file. However, neither of these solutions worked for me.
My situation:
Is Python environment selected? yes
Does the Terminal recognize Python environment? yes
Can I run the Python code from the activated Terminal? yes
Does the code run w/o error when I use "Start Debugging"? yes
Does the code run when I click "Run Code"? no
The only solution that worked for me is to:
Open Windows Terminal (or cmd)
Activate environment: conda activate <environment_name>
Open Visual Studio Code from Terminal: code
Then, "Run Code" (#5) works without any issues.
Source:
"module not found error" in VS Code using Conda - l3d00m's answer
Faced similar issue and here is how I fixed it. Remember that there are multiple ways to run your code in VS code. And for each way you may end up with different interpreters and environments. For example:
1. Creating virtual env and installing libraries
In my case I opted into creating virtual environment and doing so outside of VS Code using command prompt:
python -m venv .plotting_test
Following that I activated it:
.plotting_test\Scripts\activate.bat
Following that I installed additional libraries:
python -m pip install matplotlib
Following that I made sure to see it was all installed ok:
python -m pip list
And I also checked where for current directory:
cd
2. Point VS Code & VS Code Code Runner to virtual environment
Opened vs code, closed previous workspaces, opened new folder, created test.py as I was starting new. Pressed ctrl + shift + p. Selected ```Python: Select Interpreter``:
Followed by + Enter interpreted path
Navigated to directory from last step from section 1. Found my virtual environment folder created in step one and pointed VS code to that version's python.exe in Scripts:
Verified I am pointed to such:
Saved as workspace so that I can create default workspace settings for this project:
In workspace settings files defined paths to my virtual environment created n step 1 for workspace interpreter & CODE RUNNER(!):
"settings": {
"python.defaultInterpreterPath": "C:/Users/yyguy/.plotting_test/Scripts/python.exe",
"code-runner.executorMap": {"python": "call C:/Users/yyguy/.plotting_test/Scripts/activate.bat && python -u"}
}
}
Reloaded window just to make sure (ctrl + shift + p) = "Developer: Reload Window"
Now run code and run python file should be execute under your specified envs:
Try running pip list in VS Code to check if the module is installed, next check if your python version is correct/supports that version of SimpleITK. It may be a problem with the python interpreter that you are using for VS Code (ie. the module may be installed on a different python instance than the one your VS Code is using)
Is Python environment selected?
Does the Terminal recognize the Python environment?
Can I run the Python code from the activated Terminal?
Does the code run w/o error when I use "Start Debugging"?
if the answer to the above is "yes."
Then,
Try running the Code using the option "Run python file in terminal" (in code runner extension). And assign a new shortcut for that for future use...
How to fix module not found error in Visual Studio code?
To Solve VSCode ModuleNotFoundError: No module named X Error Make sure you are running from the package folder (not from package/module ) if you want import module. calculations to work. You can also set the PYTHONPATH environment variable to the path to the package folder.
Once you have created a virtual environment, and installed your required packages in that environment, close VS code. For Windows platform, open command prompt and navigate to the folder where your virtual env folder is created. And then launch VS code from there using the command code .
For ex: My virtual env name is .imgenv, and its inside C:\py_stuff\projects
So, I navigate to C:\py_stuff\projects and then type code .
Now, your VS code should recognize the packages !
I just ran into the same issue. I found that if I selected all text before shift enter the script would compile as a file instead of as a single line.
I had the same problem. I bet you have a shebang statement at the top of your file.
If you do.
Visual Studios settings
Under "Code-runner->Code-runner: Respect Shebang" section or just do a search for "Code-runner: Respect Shebang"
Uncheck weather to respect Shebang to run code.
Now it will run under the virtual environment and find the modules that you installed using pip! :)
I struggled with this for a very long time, and had tried almost every other answer. I wasn't using pip, so that wasn't the issue. But still VS Code wasn't finding the modules that were installed in the Selected Interpreter.
Ultimately it came down to old conflicts that existed because I switched to miniconda, and VS Code was still looking for anaconda3.
I completely wiped VS Code and its associated files (cache, preference files, etc.) from my machine (some instructions), and installed a clean version.
This now syncs as expected with miniconda.
If you have different python versions installed, be sure you install module with right one.
python -m pip install <module>
or
python3 -m pip install <module>
Run your environment from a directory not in the users directory. I solved my problem running my environment from C:\Code\ProjectA\
I discovered my problem by running:
IMPORT os
Mycwd = os.getcwd()
PRINT(Mycwd)
.venv/Lib/SitePackages is the default directory where Vscode looks for Modules.
This directory is automatically created on creating .venv via the command Pallete.
External modules installed via pip are placed in this directory by default.
Place self created modules inside this folder manually.
For mac users
In the terminal check which python you are using by command which python. It will give you the path of the python interpreter path. After that type cmd shift P and type Python: Select interpreter.
After that select + Enter interpreter path and paste the path which you got after running the command which python.

'Cannot setup a Python SDK' in PyCharm project using virtualenv after OS reinstallation

I re-installed windows and opened an existing Pycharm project and get the error 'SDK seems invalid' in Settings > Project Interpreter.
The project interpreter path is pointing to python in the venv:
MyProject\venv\Scripts\python.exe
I tried re-adding python.exe:
Thats when I get the error:
Update: here is an error from idea.log, a lot of other issues for virtual environments seem to be with windows environment variables and system paths:
2018-09-28 19:50:40,275 [ 17601] INFO - hon.packaging.PyPIPackageCache - Loaded 153296 packages from C:\Users\Matt\.PyCharm2018.2\system\python_packages\pypi-cache.json
2018-09-28 19:50:40,816 [ 18142] INFO - rains.python.sdk.PythonSdkType - Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'
Current thread 0x00000fa8 (most recent call first):
Exit code -1073740791
2018-09-28 19:50:40,816 [ 18142] ERROR - ns.python.sdk.PythonSdkUpdater - Failed to determine Python's sys.path value:
STDOUT:
STDERR: Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'
Current thread 0x00000fa8 (most recent call first):
com.jetbrains.python.sdk.InvalidSdkException: Failed to determine Python's sys.path value:
STDOUT:
STDERR: Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'
What solution is: Check out venv\pyvenv.cfg and provide a valid path to the basic python installation.
What has most probably happend:
After reinstalling your OS, you have no base python interpreter reinstalled or you have installed it at different location than before. Thus your virtual environment fails to locate the python installation. Virtual environment implies that all libraries and settings are isolated from other projects. It does not provide an isolated python installation. You still need your base python that had been used for venv creation.
My case: I have a project in a network share and try accessing it from different computers. The base python paths depend on the very PC. The solution above works fine for me. Unfortunatelly, I need to update pyvenv.cfg depending on the PC in use.
P.S. I believe that there is an environment variable to overide the venv config value. I only tried to set PYTHONPATH=C:\Anaconda3\envs\python37 on Windows and then to activate venv. It did no effect and I gave it up.
Here's what solved my problem when I faced the exact same issue
Navigate to Project Interpreter, right side of the selection box, click the gear icon, it will show two options add & show all.
Click show all, if you see the previous existence from the same directory delete that. Click on add or + sign to add a new interpreter and navigate to your project path, navigate down to the virtual environment directory.
venv/bin/{select the python executable with the version code i.e if you are using python3.6 select python3.6}
Once selected, you can now click the notice that says install packaging tools, hit apply and done.
Most probably, some path to Python environment that PyCharm tries to use has become invalid somewhere. There are (at least) two primary suspects:
Path to your virtualenv in PyCharm settings
PyCharm needs to know the path to your environment to run things in it. So, if that path changed, PyCharm's saved path has become invalid.
Go to the interpreter settings for your project in File->Settings...->Project interpreter->(Gear icon)->Show all...:
Then delete and recreate the necessary entries. Or edit them and specify correct paths.
E.g. this is what my list looks like after I deleted an Anaconda installation:
Path in the virtualenv to its base installation
Since virtualenv is not a full installation, it must have a path to its base installation stored somewhere to be able to use files from there.
As of this writing, virtualenv (v16.0.0) in Windows is implemented like this:
The real python.exe and several other files are copied into the virtualenv's subtree
In Lib\orig-prefix.txt, the path to the base installation is stored. It is used to add the base installation's Lib to sys.path via a custom site.py.
So, if the path in that file becomes invalid, the virtualenv's Python interpreter will be unable to find any standard modules except those few that were copied. Which perfectly fits your symptoms.
I currently have the same issue, that I can't install any package tool in Pycharm and that freak me out. Here is the step I fixed it, just want to share. OuO.
Step 1
Find show all in the right corner of a setting icon
Step 2
Click the + icon to open Add python Interpreter
Step 3
In New environment 's Location Under Virtualenv Environment select file
Step 4
Find your Pycharm file and make an empty file under it and click OK and keep click OK
Step 5
Now in Project Interpreter select the empty file you just create and now you should be fine to install Pycharm package.Hope this solve your problem.
In my case the problem was because I was using WSL to host my project so the project address used by PyCharm to create and select the venv was wrong. Instead of using the option Virtualenv Environment to create the environment:
You need to select the WSL option from the side bar and then enter the path to your new or existing venv.
Nothing above worked for me
I made a simple change , Hope it works for you too !!
It happens due to conflict in storing python.exe , In my case it was in F:\ drive
Solution :- Pycharm expects python.exe file to be present in some location , you can check that in project interpreter , it will show some default location where pycharm is searching to execute exe file , but issue is the exe file is not present at that location , so create the folder which pycharm was expecting to execute exe file and paste the downloaded exe file
Hope it Works for you !!
Happy Coding
Well, i'm pritty new to Python, and I did too had a re-install of my os after a crash
Old setup:
In the old system setup I used python 3.7.4. I made al my (practice)projects with that, and each project had a venv/scripts/python3.7.exe in it.... my undertanding is/was that all the files in these virtual environment where 'stand alone', so sufficient to run a python 3.7.4 for that specific projec files, and not depending on files of the home-python-dir.
The install-directory of python was c:\Program Files (x86)\python 37-32
Each project had a file [project-path]/venv/pyvenv.cfg, and in this file there was the line
home = C:\Program Files (x86)\Python37-32
then - my system crashed - reinstalled windows 10, and downloaded again python, but this time python 3.8, and it installed in C:\Program Files (x86)\Python38-32
New setup:
So, after some hairs lost - I also installed the old python version 3.7.4 in the specific path stated in the pyenv.cfg file (C:\Program Files (x86)\Python37-32). So, i had 2 python versions installed on my new system, one in .../python38-32 and one in .../python37-32
And that worked, so when I selected in 'add interpreter/existing interpreter' and pointed to the [project]/venv/python3.7.exe it worked like a charm.
So, apearantly there are files in each version-specific home-directory that pycharm/python needs - i was under the impression that the files in the .venv directory would be all it needed....
I faced this issue when I switched my system which had different python version installed at different location. The simple short solution is to open 'pyenv' file and point it to the current installation path in your current system and that's it.
I had the same problem and couldn't really figure it out.
As it was a side project the mistake was infuriating and hilarious at the same time.
My folder names had non-english letters. Specifically it had the letter "đ" and the SDK was always invalid because of it.
You might say a stupid mistake, it was, but I wasn't really paying attention.
Hope this helps somebody.
I get the issue in Pycharm 2021.2.3 when I try to make a new environment using an exe that is called anything but python.exe (I was organising my different versions by calling them python39.exe, python38.exe, etc.). I just stopped doing that and renamed all my python exes to python.exe and it started working.
go to the Edit Configuration foe edit interpreter, then remove all interpreter then ok.
now, you should add new interpreter and select the path of python.exe in your installation path(for example c:\ ),then ok.
for me, i solved this error by this solution.
The paths specified in pyvenv.cfg need to be corrected after the venv folder is copied from one computer to another. The main place to look at is the user name. For example:
Old computer:C:\Users\OldComputerUserName\AppData\Local\Programs\Python\Python310
New computer:C:\Users\NewComputerUserName\AppData\Local\Programs\Python\Python310
The path is fixed when you add interpreter to the project the 1st time. I learned it the hard way too.
This problem is because the interpreter path points to the virtual-env, instantiated to the particular project. But we don't have any python installed there.
Therefore we have to set the interpreter path to the "python.exe" file inside the python folder which we have installed on our PC.
This can solve this problem very easily.
If you haven't installed python on your machine please install it and set the path accordingly.
Thank you.
I also had this issue and it's 2023! All I can tell you is what I did to fix it. I tried the other solutions listed in this post (at least the ones I looked at) and they didn't work.
What I did was I copied the venv file in my project (for safekeeping) and then moved it elsewhere.
I deleted the venv file in my project after making my backup and I deleted the interpreter that I had been trying to use.
From there I opened up File -> Settings -> Python Interpreter -> and since there was now no interpreter and no venv folder
I created the interpreter again. Make sure to list the proper path to the version of the python exe you want to use!
From there you pretty much just apply your changes and you will see it pop up with some prompts. It will create a new venv folder for you, just accept the prompts and it worked for me.

Virtualenv won't create environment; runtime error

I'm trying to create a simple virtualenv environment; python and virtualenv are both installed. When I go in to my directory in which I am trying to make this environment, I keep getting a Windows Script Host popup box:
Script: *My path to virtualenv.js*
Line: 1
Char: 1
Error: Object expected
Code: 800A138F
Source: Microsoft JScript runtime error
I went in to my file to see where the problem may have lied and assumed it was just a module I hadn't installed yet, though all of them are in the node_modules in my package. I'm not sure where else this issue is coming from?
It looks to me as if you have a virtualenv.js JavaScript file on your path, and that JS files are associated with Windows Scripting Host on your machine. (Perhaps you have the node-virtualenv project installed, which puts a JavaScript file with the name virtualenv.js in your path?)
To create a typical Python virtual environment, you want to invoke the (Python) virtualenv.py script. Assuming you've installed virtual environment with:
pip install virtualenv
Then you can use:
python -m virtualenv ENV
to invoke the Python interpreter directly, and have it load the appropriate virtualenv.py script file on your path.

Installing easy_install with setup tools

I'm trying to install easy_install using setup tools for the purpose of installing scrapy on Windows XP. On the setup tools page it says:
Once installation is complete, you will find an easy_install.exe
program in your Python Scripts subdirectory. Be sure to add this
directory to your PATH environment variable, if you haven't already
done so.
But when i install I only find an easy_install.exe.manifest file, and I'm not able to run this file. Sorry if this is a stupid question, but I'm new to this. I'm not quite sure what this sentence means either:
Be sure to add this directory to your PATH environment variable, if
you haven't already done so.
It means that you should have the path to the directory containing the file when you do
echo %PATH% (windows)
echo $PATH (linux/cygwin/...)
in the command line. If it does not appear, you should add it.
To do so check out the following links
git - setting path variable (linux)
How to set ANT_HOME with Windows? (windows)

Categories