Trying to use numpy in intellij, But it won't work - python

I tried the command in my cmd and this is what is said, I don't really know what it means though, and I still can't use NumPy in IntelliJ.[This is the whole thing, it says NumPy isn't there even though I find it in the external libraries when I go through them.]

Make sure that your IDE (wherever you're running your Python program) runs in the same environment that the one where you install your packages. It appears like you have 2 environments: One with "native Python" installed in your machine (where your program runs), and an Anaconda environment (where you installed numpy).
I recommend you stick with Anaconda and use it only. In your Start Menu, search for "Anaconda Prompt". There you can install any packages you want, but it seems numpy is already installed. Then you can type, for example, code to open VS Code, or jupyter notebook to run Jupyter. Or type python and start coding.
But if you really want to use a program outside Anaconda environment, then you have to install your packages in your "native Python" environment. You can do such using the Windows cmd or PowerShell, instead of Anaconda Prompt.

Related

Autorun of a script containing libraries not imported in the environment

I am new to python. I need to configure python script autorun through windows task scheduler and I have a problem.
I have a python (.py) script from jupyter notebook. This script contains the import of libraries (like "import numpy") that are in the conda environment. It performs well in jupyter. But when I try to execute it in the python interpreter (C:\ProgramData\Anaconda3\python.exe) first I get an warning:
"This Python interpreter is in a conda environment, but the environment has
not been activated. Libraries may fail to load. To activate this environment
please see https://conda.io/activation"
second, after "import numpy" I get an error.
Here I learned that conda do not support python.exe activation.
So, how can i get python.exe with activated environment (pre-installed libraries) for use in windows task scheduler?
Maybe there are other ways to autorun the script?
There are two ways that i run scripts with the task scheduler in windows 10.
create a batch file: *.bat
point the task shceduler to the python file and also the python executable.
If the script contains the import, this will not be a problem as long as you have that particular module installed.
In your case you need to pip install numpy to the same version of python that you will be running in the task scheduler.
So, for example, if you run version 3.9 from the task scheduler, then you need make sure that numpy is installed for version 3.9.
I have not used conda. I always use pip which i know works, but i would expect conda to be nearly identical.
In terms of getting python, you can simply go here and download the latest version: https://www.python.org/

Different versions of Python, packages and many terminals in Anaconda

I am using Windows 7 and already installed Python version 3.8.10. After installing Anaconda 4.9.0, I open Jupyter Notebook and see that Python has a brother, version 3.8.3. Should I remove one?
Not only that, all Python packages in Jupyter have different versions than existing ones. I also find out now there are a lot more terminals: one is from drop-down "New", one is called Anaconda prompt and the last one is Anaconda Powershell prompt, not to mention the usual windows terminal.
Can anyone please give a simple explanation about this and please indicate which terminal should I use to install and upgrade packages for Jupyter Notebook?
Been a while I used windows, but I'll tell you this. Anaconda is a suite of tools and you don't have to use everything. Anaconda prompt and Anaconda Powershell are basically the same, it's just that the Anaconda prompt uses a Windows command prompt while the other uses a Windows Powershell as a base.
I'll say use the Anaconda prompt since it should feel more welcoming and easy to use.

Anaconda Environment on VS Code

In general I am new to python so keep it easy. I have started my coding in Spyder since it was easy to install libraries with Anaconda.
Now we want to switch to VS Code for version control. I have switched interpreter and python path to Anaconda folder, but if I open python files I have created in Spyder I can't use in VS code, issue always is with importing libraries.
Screenshot
The first rule with Anaconda is to not manually mess around with the paths. Anaconda has a different philosophy: Before you can use Python, you need to activate a conda environment.
c:\> conda activate
(Anaconda3) c:\> python
>>>
VSCode detects conda environments and you just have to select one for your project (Python: Select interpreter). Now open a new terminal and watch VSCode activating the environment for you (like shown above).
However, when you start your script for the first time, VSCode sometimes invokes the interpreter even before the conda activation has finialized. Then simply restart your script.

Can I install Anaconda alongside Canopy?

I need to install Canopy, but I have Anaconda already installed. If I install Canopy will there be conflict or not? an if will be what are the possible problems?
Multiple Python installations can co-exist on a system, but it is important to keep them isolated (none should be set as default or referenced in any environment variable).
Canopy will not set these at all, so will not interfere with Anaconda. You can run Canopy Python scripts from inside Canopy. If you want to run them from a Terminal / Command Prompt, you can open it from the Canopy Tools menu.
To avoid possible interference of Anaconda with Canopy, please modify your PATH or PYTHONPATH environment variable to remove any references to Anaconda or any other Python installation using the instructions in this article as a guide (note that in this case you would be removing Python from this variable).
You may wish to write a small batch file or shell script to re-insert any such references temporarily when you do want to run anaconda.
I have not used Canopy but use system installed Python and Anaconda a lot so I can explain some issues people run into. When you have 2 different python installations there will be a problem of which Python is used(Type python at the command prompt and which one opens the interpreter?). Usually the executable Python location is added to the PATH so if 2 are in your PATH it will use the first one. With this you will likely have a mess with environments. If you go to use Canopy's Python you will not access Anaconda's Python packages and vice versa.
Other weird issues can come up if one python package picks up a .so or .dylib file that doesn't work or isn't the specific version. One installation may remove a version of these in favor of it's dependent version and then another piece of code no longer works.

Running different kernels (e.g. Python 2.7) on Juypter

I have Python 2.7.10 (which I just installed) and I recently installed Jupyter. However the only kind of notebook I can create when I open Jupyter is iTorch and Python 3.
How can I create a notebook in Python 2.7?
I'm attempting to complete a TensorFlow tutorial and that is written in Python 2.7.
The best way to run multiple versions of Python is with virtual environments. Then you can run whatever version you like whenever you like. A great way to do this for people who don't want to spend a lot of time working on it (like me) is with Continuum's Anaconda distribution of Python. I couldn't get the hang of virtual environments till this came along.
Before going any further, I recommend uninstalling the Python 2.7 you installed, and reverting to your system's Python as far as possible.
Then install Anaconda. Install the Python 3.5 version since you'll want to use that most of the time. Almost all libraries I use support it now. Google App Engine and TensorFlow are the only things I use that don't.
Now you should be able to create a Python 2.7 environment like so:
conda create -n python2 python=2.7 anaconda
The python2 is just the name; call it whatever you like. The anaconda bit installs the scientific Python stack; you can leave that off if you want a very basic environment.
Creating the environment doesn't start it. Start the environment with:
source activate python2
Add it to the notebook with:
ipython kernelspec install-self --user
Now install TensorFlow using whichever command Google recommends for your system.
Whenever you want to use that environment, do the source activate command again. To leave it, start another environment or type source deactivate. You can make as many environments as you like, with whatever versions of Python and whatever other packages you want.
Read more about managing environments.

Categories