So here is my story:
As we know macos comes with pyhton 2.7 preinstalled. Years ago, I installed python 3.7.0 and all going good. I started working with Tensorflow and during that time tensorflow wasn't compatible with 3.7.0 so switch the version to 3.6.6 somehow :). After some time i installed anaconda and it installed 3.7.3.
At this point:
When i open my python IDLE shell, it runs on 3.6.6
anaconda Jupiter notebook shows 3.7.3.
Then i learned to create virtual environments through terminal and i use following code to create virtual environment:
pip install virtualenv
virtualenv project_env
And after i activate the virtual environment the python version it shows is 3.7.3.
Then recently i changed the terminal shell to zsh and now everything is kind of messed up. I'm
Terminal can't find conda commands. How to fix that?
Now i can't create virtual environment through virtualenv project_env. It says command not found. Why? It use to create virtual environments with python 3.7.3.
Now to create virtual environment i use python3 -m venv project_env this creates the virtual environment with python 3.6.6. If i use python3.7 -m venv project_env it creates environment with python 3.7.0.
I can't find a way to create virtual environments with python 3.7.3.
I need help with above troubles caused after installing zsh and help with accessing python versions wherever i need. How do i update python version 3.7.0 to latest or any specific version like 3.7.3. Hows python 3.8.4 to use, i mean like i had trouble importing tensorflow in python 3.7.0.
I hope you will understand my trouble and searched a lot for solutions. I'm so confused right now, couldn't even figure out the title of my problem.
Based on the fact your shell can't find conda now, you should look at your "path" environment variable. Whenever you change from one shell to another, you need to look at and possible create or modify the files the shell uses upon startup. These files setup your environment (PATH, PYTHONPATH, etc), create aliases, etc. You may need to create the .zshrc, .zprofile, .zlogin etc files and add the same settings as your previous shell's startup files.
Example:
If you used the bash shell previously you would need to modify the .zshrc file to include your settings in the .bashrc file. Syntax may be different, so a straight copy may or may not work.
Try this as a quick temporary fix (may or may not work, depending on your current ~/.profile settings:
Create a ~/.zprofile file with this code inside:
emulate sh
. ~/.profile
emulate zsh
references:
https://superuser.com/questions/187639/zsh-not-hitting-profile
http://zsh.sourceforge.net/Intro/intro_3.html
Related
I have had trouble for months using packages and libraries in VS Code. Everytime I create and activate a new python virtual environment in VS Code, it defaults back to using the MacOS pre-installed python 2.7.10. A picture below shows my issue. I would like to see "/usr/local/bin/python3" when I type the command "python --version", instead I get "/usr/bin/python". Does anyone know how to fix this? Thanks.
Picture of problem
I'm not a MacOS user and can't see your picture due to my network, but you can create the virtual environment with a specific version of Python.
On Windows this is:
python3.8 -m venv envname
If you are creating a virtual environment by using python -m venv envname the issue is the default interpreter on your PC is set to Python 2. A quick search shows you might be able to set a different global version on a Mac with something like pyenv global 3.8.6. I'm not sure if this would have other implications for you.
Please try to open a new VS Code terminal to let it reload the currently selected python environment. (Terminal; New Terminal; shortcut keys: Ctrl+Shift+`)
For the global python environment in VS Code, even though we have switched the python environment, sometimes its internal terminal still uses the first python of the python environment variable. Therefore, it is recommended that you move the python you need to use to the first: (Please reopen VS Code after setting.)
I have an Anaconda distribution installed on Mac OSX (10.14.2). With it, I installed VSCode which I'm to write python scripts. Recently, I've updated some environments in Anaconda and something happened with the configuration of the python path VSCode uses for its integrated terminal: when I run my code, an ImportError comes up for the joblib package that I now have installed in my conda environment (also happens for other packages), which doesn't happen when I run the same code in a regular terminal.
Using conda list in the integrated terminal gives me the correct list of packages for the environment I'm using, and conda env list indicates that indeed this specific environment should be active. However, I can see that that something is off, because in my normal terminal I get:
$ which python
python is /Users/Joris/anaconda3/envs/astro3/bin/python
python is /usr/bin/python
While in the VSCode terminal:
$ which python
python is /usr/bin/python
python is /Users/Joris/anaconda3/envs/astro3/bin/python
I've tried changing some of the VSCode settings, like manually pointing python.pythonPath and python.venvPath to my anaconda environment folders. (The setting python.terminal.activateEnvironment is set to true.) Also, reinstalling VSCode through the Anaconda distribution does not seem to help. So unfortunately, I can't seem to get VSCode to run python with my Anaconda environment which contains the packages I need.
Press (macOS): ⇧+⌘+P, (Linux/Windows: Ctrl+Shift+P) in VS Code.
Type: python select interpreter
Select /Users/Joris/anaconda3/envs/astro3/bin/python
Test if your lib is usable.
I was required to install anaconda for a CS course and used spyder and Rstudio.
Then, for a different class I used pycharm.
When I type on the command line "python -V" I get:
Python 3.6.1 :: Anaconda 4.4.0 (x86_64)
and I have no idea why it relates the python version I have installed with Anaconda (and why not pycharm?). I understand that the OS runs python 2.7 (shouldn't I get that instead? and when I type python3 -V get which version of python 3 I have?) and when I use something like Pycharm or Spyder I can choose which version I want from the ones I have installed and use it within the program, not for the terminal.
I just want to have everything in order and under control. I don't think I understand what Anaconda really is (to me is like a program that has more programs in it...). How do I keep anaconda to itself ? 1313
Also, should the packages I installed through Terminal work on both pycharm and spyder/anaconda even though when I used pycharm I used python 3.5 and anaconda 3.6?
I think I need definitions and help to get everything in order in my head and the computer.
Pycharm is just an application to help you write code. Pycharm itself does not run python code. This is why in PyCharm, you need to set the interpreter for a project, which could be any python binary. In PyCharm, go to Preferences > Project > Project Interpreter to see where you would set the python environment being used for a given project. This could point to any python installation on your machine, whether that is the python 2.7 located at /usr/bin/python or a virtual environment in your project dir.
The industry standard way to "keep things in order" is to use what are called virtual environments. See here: https://docs.python.org/3/library/venv.html. A virtual environment is literally just a copy of a python environment (binaries and everything) so whatever directory you specify. This allows you to configure your environment to however you need in your project without interfering with other projects you might have. For example, say project A requires django 1.9.2 but project b requires 1.5.3. By having a virtual environment for each project, dependencies won't conflict.
Since you have python3.6, I would recommend going to you project directory in a terminal window. Running python -m venv .venv to create a hidden directory which contains a local python environment of whatever your 3.6 python installation. You could then set your project interpret to use that environment. to connect to it on the command line, run source .venv/bin/activate from where you created your virtual environment. run which python again and see that python is now referencing your virtual environment :)
If you are using a mac (which I believe you are from what you said about python2.7), what likely happened is that your anaconda installer put the Python bin directory on your PATH environment variable. Type in which python to see what the python alias is referencing. You can undo this if you want by editing your ~/.bash_profile file if you really want.
You are more or less correct about anaconda. It is itself another distribution of python and contains a load of common libraries/dependencies that tend to make life easier. For a lot of data analysis, you likely won't even need to install another dependency with pip after downloading anaconda.
I suspect this won't be all too helpful at first as it is a lot to learn, but hopefully this points you in the right direction.
The interpreter I use is
and it works in virtual environment. I have both anaconda and python interpreter installed in my system
But if I want to install something using pip for instance "Flask" then it happens
I am using Linux Mint 18.1 Serena"
And the way I tried to create the virtual environment is
Lastly there is no space in the directories where I tried to create virtual environment
Then I tried this link
Specifically the following commands
All those things didn't solve my problem and lastly I ended with the following errors each time I open my shell
Then I change my source of bashrc & bashrc-org to
virtualenv
export WORKON_HOME=~/virtualenvs
source /home/cryptosilicon/anaconda3/bin/python
Now get the following error
How do I correct the error and make the pip work inside virtual environment ?
I just solved (or at least found a work-around) for a similar problem.
I am using Linux Mint 18 and python 3.
I was trying to install a dependency inside a Python virtual environment using pip and it would fail (and actually pretty much mess up my whole virtual env).
The message was : "bad interpreter: No such file or directory".
But I noticed that the referenced path was actually truncated at the first space.
So I tested an virtual env in a folder for which path there is no space and it worked.
I am attempting to create a virtual environment that uses Python 2.7.11 (rather than Ubuntu's 2.7.6). I can successfully create the virtual environment using the following code:
virtualenv -p /home/stmist/opt/Python-2.7.11/bin/python2.7 ~/test
However, running the following code:
source ~/test/bin/activate
python -V
indicates that the virtual environment is running 2.7.6. Any suggestions?
Update:
When inside the virtual environment, "pip" modifies packages for 2.7.11, not 2.7.6. I can run Python 2.7.11 using /home/stmist/opt/Python-2.7.11/bin/python2.7. So, the virtual environment is usable, but not ideal.
After restarting my computer, the virtual environment is now using Python 2.7.11. I don't know whether this is due to the restart, or something else along the way. Thanks to everyone for your help.