Tensorflow Installation Confusion - python

When I try to install TensorFlow using pip in the terminal (I'm on Mac), it says that I have it downloaded. The problem is when I try to use import tensorflow in pycharm it says that I do not have it installed. Please help.

Check your project interpreter on PyCharm. Based on your description, it seems like you might have installed TensorFlow on your base. If PyCharm's interpreter is using a different environment (that is not your base environment) to run Python, you will not be able to access TensorFlow. PyCharm allows users to configure environments and interpreters very easily.
I recommend that you use a virtual environment for your projects, since it allows you to manage different modules and installations more conveniently. For more information on Python virtual environments, refer to this post.
If anything is unclear, I'd be happy to elaborate.

Related

If I install anaconda, do I still have to use vscode?

I'm new in programming, actually I use it for Machine Learning.
I have installed python and anaconda (I don't know if that is right, or I have to install only anaconda?).
And I can see in start menu: (Anaconda powershell, Jupyter, Spyder, Anaconda navigator, Anaconda prompt).
So my question is: Do I still have to use vscode as IDE, or one of the listed programs that come with anaconda? If the answer is the second choice, I will ask, which one of them?
Thanks.
I'm using python just because I have a project in ML, So I must to set the necessary things for ML, like libraries, dataset, and algorithms. Then I have to learn how to use them.
Any help will be very apprecheated.
Anaconda is a Python distribution, that not only comes with Python itself, but a lot of additional Python packages from the "scientific stack", like numpy, pandas, matplotlib, scipy, scikit-learn: exactly what you need for ML. You don't have to install anything else from python.org.
Anaconda also comes with the Spyder IDE. This is the perfect choice for a Python beginner. You don't need VSCode. VSCode is way more flexible than Spyder, but you have to get used to it.
Conda is the package manager that comes with Anaconda. Do yourself a favour an learn some conda basics and how to use virtual environments here: https://conda.io/projects/conda/en/latest/user-guide/getting-started.html
The important difference between Anaconda and pure Python is that you have to activate a conda environment - even the "base" environemnt - before you can use it. This is not obvious to a beginner.
If I were you I would use vcscode. Anaconda is only a python with extra features, but to code you would appreciate the VSCOde. It comes with many features and you can install extensions to burst your experience. Go for it.

Installing a second python environment I’m mac

I’m trying to figure out how to install a second python environment alongside anaconda.
On windows I can just install python in a different folder stand reference the desired python environment using env variables. I’d like to do the same on Mac.
A virtual env won’t do the trick as it does not copy the standard library and other things. It needs to be a complete stand alone environment. I guess I could compile it, but is there an easier way?
Thank you very much for any input.
You can do that using pyenv.
It allows you to have several python versions, and even different distributions.
It works, mostly on user space. So, no additional requirements are needed (apart from compilation tools)

Jupyter Notebook cannot find certain modules

As part of a web scraping class I've been instructed to download a few modules from the command terminal (requests, bs4, lxml). These have seemingly been successfully downloaded to my computer, yet my Jupyter Notebook AND PyCharm virtual environment cannot find them.
I am a beginner so I'm sure there are some big things I'm missing, any help would be appreciated.
How did you install Jupyter?
Wich package manager are you using? (eg. what did you type to install the packages?)
Wich modules can it find and which not?
Usually you want to make sure your modules are available in the environment you are using. ( Enviornments are like "versions" of python. You could run multiple versions like 3.7 and 3.9 on your Computer but also also different builds from one python version.)
Pycharm builds its own environment. Make sure you use the enivorment you installed your packages to in Pycharm. Pycharm allows you to modify and create new environments very easily
For PyCharm it might be useful to check out their help page.
I figure this could help: https://www.jetbrains.com/help/pycharm/configuring-python-interpreter.html#add_new_project_interpreter
The interpreter is basicly the a customized version of python. Pycharm keeps track of the modules you need for every project. So you want to create/select an interpreter which has the packages you have installed.
hope it helps
cheers

Use anaconda in pycharm (Import libraries error, updating anaconda and virtual environment)

What I was doing before
When I start using Anaconda in pycharm before, I installed Anaconda and after that I installed pycharm. Running the pycharm and in the following menu (following image) I did choose the ~/Anadaconda/python.exe path for the pycharm interpreter and I used this interpreter for all my project. I hadn't any problem.
Question 1: Is this procedure correct?
There is something called Virtualenv Environment in the picture. As far as I know, this makes a project and its dependencies isolated. I didn't fully understand what is the use of that though.
Question 2: What is the use of isolating the projects? Why should I do that? (an example would be helpful)
Of Course, there is a benefit and use of that, so 3rd question comes here.
There is a checkbox that says Make it available for all project Is still this option follows being isolated?
Real Problem
The problem starts a week ago when I want to install the new version of Anaconda 3.5.1. and I did. but I wish I didn't.
After doing that, for every package I import to my project, I get an error, it seems like, it doesn't recognize them at all.
for e.g. Numpy:
module = self._system_import(name, *args, **kwargs)
ImportError: DLL load failed: The specified module could not be found.
During handling of the above exception, another exception occurred:
For sklearn:
ImportError:
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try git clean -xdf (removes all
files not under version control). Otherwise reinstall numpy.
Original error was: DLL load failed: The specified module could not be found.
Tired reinstall both pycharm and anaconda for a few times. I'm getting crazy about this.
The procedure you use to setup the interpreter is correct. The use of isolating projects is that you don't get in trouble with package dependencies. Some projects could require different versions of, for instance the sk-learn package. Isolating projects by using environments and installing seperate packages for every project prevents any issues with this. "Make available to projects" has nothing to do with isolation of packages inside that environment.
The problem here is that you probably did not tick the option 'Add to path' while installing Anaconda. PyCharm does not automatically activate your environments when you do not add Anaconda to path. Using PyCharm with an unactivated environment is unsupported, and can lead to import-errors like the ones you specify. So to solve your error, use anaconda prompt, activate your environment and launch PyCharm from there, or re-install anaconda/mini-conda with the option "add-to-path" checked. A detailed discussion of this problem can be found here.
Yes, a virtual environment is exactly that.
Using a virtual environment is kind of a clean slate. You wouldnt want you to use a environment for a web crawler that has Django in it. And in your Django site you wouldnt want to have BeautifulSoup in it. This is the best way of managing environments within different projects. I would highly recommend setting up a virtual environment for each project you create.
Now when you are getting these errors. First do you have pip updated to the latest version? When installing numpy are you using a CLI or the using the pycharm wizard thingy?
Sometimes when you get errors installing you can use easy install instead of pip and it can resolve the issue.

Running pip3 on MacOS Sierra (Python newbie) - do I need a virtualenv?

I'm running MacOS Sierra 10.12.6
By default the system came with Python 2.7.10
I installed Python 3.6.3 (with IDLE) so I can learn Python (3). I understand that this is normal as MacOS may rely on Python 2.x for some programs. Either way, Python3 runs just fine if I run python3 from the command line/terminal, or if I use IDLE (which defaults to Python 3).
Now I want to install some libraries like Beautiful Soup.
And I believe I can install it as follows:
pip3 install beautifulsoup4
which should automatically install it. However, I read that it's recommended to use virtualenv on Mac BEFORE I run the above command. As a newbie, I don't want to mess anything up on my PC, so can anyone point me out how I can do this correctly?
For example, I can follow this link: http://sourabhbajaj.com/mac-setup/Python/virtualenv.html
But I just want to write here to make sure I'm following the right article/commands before I do it. Just being super careful!
Also, can I make a folder with my "virtual environment" and then add sub-folders inside that for each project? Meaning, I don't need to do this everytime, I have one virtual environment and any project that I do just is a subfolder within that space so I can use any libraries that I installed. Just trying to grasp the concept.
Thanks!
Sorry to add confusion.. this can be a tough subject for someone starting out.
The official docs recommend venv, which is similar to, but slightly different than virtualenv.
I would strongly recommend pycharm. It will create your venv for you as part of your project, which you might find helpful.
[Edit: Some other virtual environment features of pycharm that will help you].
If you type in an import statement for a package that isn't installed, it will offer to install it for you.
typing alt-F12 will bring you up a console with your virtual environment active
It syncs up your requirements.txt document for you
It manages your virtual environment path for you (as long as you are running inside pycharm), helping avoid import problems that many newcomers have with virtual environments.
I am not affiliated with pycharm, btw -- I just think it is a great tool for python developers, especially for newcomers, and its treatment of virtual environments is especially helpful.
You create one virtualenv for each project as a way of keeping track of the specific dependencies to keep them minimal which then makes it easier when you want to share projects with other people.
But this is not something you need. No harm comes from installing packages in your real environment as well. So you can safely run
pip3 install beautifulsoup4

Categories