PATH variable not updating in Spyder - linux

first, I'll describe the problem. then I'll describe what I've tried. note that I am a novice in working with environment variables.
the problem:
In Spyder, I get a "module not found error" from certain libraries I've installed via pip, including tables and tensorflow. However, in Visual Studios these modules are successfully imported.
what I've tried
inspecting the directories the VS environment looks in, then adding these to $PATH in Spyder via the PYTHONPATH manager. To determine the directories VS looks in, I typed "echo $PATH" in the VS terminal emulator. I got a list of paths (see below). I then went to Spyder and added each of these paths via the PYTHONPATH manager.
found the locations of "tensorflow" by searching for "tensorflow" in Finder. I then went to Spyder and added each of these paths in PYTHONPATH manager.
outcome: PYTHONPATH and PATH do not change
In the terminal emulator in Spyder, I check to see if PYTHONPATH and PATH are updated but they are not.
in the python terminal emulator, this is the output:
!echo $PYTHONPATH
/Applications/Spyder.app/Contents/Resources
!echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin
For reference, in the VS terminal emulator the PATH and PYTHONPATH variables are as follows:
(base) rahel-gerson:~ rahelmizrahi$ echo $PYTHONPATH
(base) rahel-gerson:~ rahelmizrahi$ echo $PATH
/Library/Frameworks/Python.framework/Versions/3.9/bin:/Library/Frameworks/Python.framework/Versions/3.8/bin:/Users/rahelmizrahi/opt/anaconda3/bin:/Users/rahelmizrahi/opt/anaconda3/condabin:/Users/anaconda3/bin:/anaconda3/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Apple/usr/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands
parsed version:
note that I couldn't find some of these paths, like "/anaconda3/bin:". Perhaps I parsed the list incorrectly? (I thought that after a colon is a new path)
/Library/Frameworks/Python.framework/Versions/3.9/bin:
/Library/Frameworks/Python.framework/Versions/3.8/bin:
/Library/Frameworks/Python.framework/Versions/3.7/bin:
/Users/rahelmizrahi/opt/anaconda3/bin:/Users/rahelmizrahi/opt/anaconda3/condabin:
/Users/anaconda3/bin:
/anaconda3/bin:
/usr/local/bin:/usr/bin:
/bin:
/usr/sbin:
/sbin:
/usr/local/share/dotnet:~/.dotnet/tools:/Library/Apple/usr/bin:
/Library/Frameworks/Mono.framework/Versions/Current/Commands

Related

All Python scripts stopped working: path changed in all projects after macOS Monterey 12.6 update

After updating macOS Monterey today to 12.6 all my Python projects/scripts have stopped working.
Checking the symlink of a Python binary in one of my project's venv, I see the original to be:
/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/bin/python3.9
which is not in path list!? 🤔
Installed with the macOS update today?
it seems that all the symlinks to Python in the virtual environments of all of my VS Code projects now point to the binary above, and none of the projects work anymore, all with ModuleNotFoundError.
How can I get all my projects to work again?
Background/details:
.bash_profile:
# Setting PATH for Python 3.8
PATH="/Library/Python/3.8/bin:${PATH}"
export PATH
.zprofile:
PATH="/Library/Python3.9/bin:${PATH}"
export PATH
eval "$(/opt/homebrew/bin/brew shellenv)"
.zshrc:
export PATH=$PATH:/Users/xxxx/Library/Python/3.8/bin
The scripts run with venv activated ((venv)...), confirmed with which python which accurately returns the path of Python in venv (though symlinked to the weird path).
When trying to (re)install those libraries, with venv still active, they get installed in root Python with following warning:
WARNING: The scripts f2py, f2py3 and f2py3.9 are installed in '/Users/xxxxxx/Library/Python/3.9/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
I'm using /bin/zsh when run in VS Code. Same from stand-alone terminal window.
I shared Bash above as listed in paths.
tried:
echo $PATH
returns (edited for readability):
/opt/homebrew/bin:
/opt/homebrew/sbin:
/Library/Python3.9/bin:
/usr/local/bin:
/usr/bin:
/bin:
/usr/sbin:
/sbin:
/usr/local/MacGPG2/bin:
/Library/Apple/usr/bin:
/Users/xxxx/Library/Python/3.8/bin
notes:
the last path (/Users/..) seems to be the one used by Bash but not Zsh/VS Code/. This was working as is before the update though.
need to add missing path: /Users/xxxx/Library/Python/3.9/bin
checking paths one by one:
/opt/homebrew/bin: no Python binary in folder
/opt/homebrew/sbin: no Python binary in folder
/Library/Python3.9/bin: folder Python3.9 does not exist
/usr/local/bin: /usr/local/bin/python found +++
/usr/bin: /usr/bin/python3 found +++
/bin: no Python binary in folder
/usr/sbin: no Python binary in folder
/sbin: no Python binary in folder
/usr/local/MacGPG2/bin: no Python binary in folder
/Library/Apple/usr/bin: no Python binary in folder
/Users/xxxx/Library/Python/3.8/bin: no Python binary in folder 🤔
not returned with echo $PATH / need to be added: /Users/xxxx/Library/Python/3.9/bin also no Python binary in folder 🤔
not listed but symlinked now in all projects: /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/bin/python3.9
I had the same issue in VS Code running notebooks. I uninstalled and reinstalled the Jupyter extension. Then when attempting to run a notebook for the first time again, there is a prompt to install jupyter notebook. Once done, all the notebooks are running fine again for all the environments I am using.

Numpy and pygame not imported as it should [duplicate]

My Flask App server is running but I have three imports that cannot be resolved.
I have tried:
reinstalling the imports individually
reinstalling requirements.txt
I configured VSCode Workspace with an extra path to my project folder (there is now a .vscode file within the root of my project folder where it was not before)
I have updated my venv path settings in VSCode
Here is my file structure:
- > .vscode
- > client *(React front end)*
- > data
- > server *(Python/Flask back end)*
- > app
- > venv
- config.py
- README.md
- requirements.txt *(this contains the 3 unresolved, along with several that are resolving)*
- .env
- .flaskenv
- .gitignore
- requirements.txt
Unfortunately none of these things have resolved my imports issue and my routes are still not working. Any ideas/suggestions?
Open the Command Palette (Ctrl+Shift+P), then select the Python: Select Interpreter. From the list, select the virtual environment in your project folder that starts with .env.
Run Terminal: Create New Integrated Terminal (Ctrl+Shift+` or from the Command Palette), which creates a terminal and automatically activates the virtual environment by running its activation script.
Install sqlalchemy and mongoengine with command pip install. Once installing them successfully, there will intellisense when you import them and no warnings shown.
Besides, the folder .vscode is to store Workspace settings as well as debugging and task configurations.
If you are using a virtual environment, and even after trying pip installing all the necessary libraries, you have to select the python interpreter that exists in the virtual environment folder.
(Ctrl+Shift+P) then search for "Python: Select Interpreter"
Click "Enter interpreter path" followed by "Find.."
Navigate to your project virtual environment folder
Go into "Scripts" folder and then select "python.exe" as the interpreter.
These steps allow you to select the right python interpreter associated with the project's virtual environment.
Open the Command Palette (Ctrl+Shift+P), then select Python: Clear Cache and Reload window.
Voila, all the import errors vanished.
I specified a path to the python interpreter I'm using within the settings.json file contained in the project repo's .vscode folder.
"python.pythonPath": "path-to-interpreter.python.exe"
Thanks to the following resource! https://dev.to/climentea/how-to-solve-pylance-missing-imports-in-vscode-359b
I ran into this error after an upgrade of my local python version (brew -> manual install), even though the specified interpreter was already /usr/local/bin/python3.
CMD + Shift + P and re-selecting the [same] interpreter fixed the error.
In hindsight, I suspect that a restart of VSCode could have also fixed this. 🤷‍♂️
Perhaps VSCode is using the incorrect Python path for this reason. A base interpreter should be used instead of the vscode interpreter, if necessary.
After verifying my Python interpreter was sourced correctly in VS Code, I simply cleaned my env and reinstalled the project locally and the import errors disappeared. I personally had an odd VS Code/Pylance cache and reinstalling the dependencies and modules fixed it for me.
I was getting the very same error you have and none of the solutions presented here worked me.
I work on a windows machine. I use miniconda to manage my virtual environments. And when I'm coding I launch every program from the command prompt (cmd), including Vscode.
Even tough inside Vscode the python evironment was correctly settled I was getting the very same import error that you mention. The interesting part of it was that I wasn't having any problems to run the code, it was working as usuall. But when coding I wasn't able to see the functions related to the libraries with the import error.
The solution:
Activate the correct conda env for the project before launch Vscode from the command prompt.
Why does this happen?
I BELIVE that this happen because when you don't activate any conda env before launch Vscode. The base conda env is loaded as default. That generates the import conflict. (You can chek this out installing those packagues into the environment and running everything just as you have been doing)

Add libraries to PYTHONPATH In Pycharm (Windows 10)

When setting up a Pycharm development environment, I am trying to follow the following instruction, which is for Linux environment. However, my system is virtual environment created by Anaconda, running on Windows 10. How to add Pythonpath in Pycharm with respect to this kind of environment?
Add Libraries to PYTHONPATH
When running locally, the tensorflow/models/research/ and slim directories should be appended to PYTHONPATH.
This can be done by running the following from tensorflow/models/research/:
# From tensorflow/models/research/
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
Note: This command needs to run from every new terminal you start.
You may follow the following steps:
Get the Python executable path for Anaconda:
Go to window's "programs" and search for "Anaconda Command line" then right click on the properties and copy the path then go to the cmd terminal and type the path and then type python.exe at the end till you logged in the python interpreter. This may vary from an OS to another but this works for me under windows 7.
In Pycharm: Add a new Python interpreter by following exactly the instructions listed in https://www.jetbrains.com/help/pycharm/configuring-python-interpreter.html.
Use the Anaconda python executable path you got in step1 for the new interpreter called "Conda" for example. Set the new project to use "Conda" interpreter instead of the normal default Python interpreter.
Apply the new changes and restart Pycharm. Open the Settings/Preferences dialog box, and click Project Interpreter page to make sure that the project is pointing to "Conda" interpreter.
Hope this will help!

Issue with $PYTHONPATH

I get the following message when trying to run virtualenv . --no-site-packages
You are attempting to install a package to a directory that is not
on PYTHONPATH and which Python does not read ".pth" files from. The
installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:
/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/
and your PYTHONPATH environment variable currently contains:
''
However, when I echo my PYTHONPATH, I see the path from the default setting:
/usr/local/python-3.3.1/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/:/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/
So my PYTHONPATH does contain the directory I am installing to.
Anyone have any ideas what is going on?
Turns out I needed to use virtualenv-3.3, not virtualenv.

How to set a windows env variable from cygwin .bashrc?

Background: I am trying to run a windows-installed version of python from within cygwin, rather than the cygwin version (some packages I am using prefer the non-cygwin version). The following post got me up and running: Using Windows Python from Cygwin. However, I am now having an issue.
Problem: The PYTHONPATH variable does not seem to be working for me. I try "import module1" when I am using python in an arbitrary directory. module1 is located here: c:\cygwin\home\mcsefl\testFolder\module1.py. And my PYTHONPATH variable is set in my .bashrc file in the following way: "export PYTHONPATH=$PYTHONPATH:/home/mcsefl/testFolder". However I still get a "No module named..." error.
Alternate tries: Since I am running the Windows Python, I thought perhaps python did not care about the cygwin environment variables (not sure if this is true..?) So, I also tried to set the windows PYTHONPATH env variable in the control panel of windows with no luck as well.
Thanks in advance
I deleted the line in my .bashrc file that tried to set the PYTHONPATH variable and just let it be set by Windows. This corrects the problem.
Side note: The title for this Question is a misnomer now that I re-read it. My issue was resolved without addressing that overall question

Resources