PyCharm does not run – Project Interpreter problems - python

First of all, I want to note that I've read a lot of links related to my problem.
I have some problems with running the code when I want to import a module.
Here is an example of the code:
import numpy as np
Then PyCharm gives me an exception:
Traceback (most recent call last):
File "/Users/Alexander 1
2/PycharmProjects/Coursera/Week1/Vectors/Vecors.py", line 1, in
import numpy as np
ModuleNotFoundError: No module named 'numpy'
Process finished with exit code 1
I have read this and did all what was written. However, it hasn't been working. I've reloaded the PyCharm – no result.
Help me, please! I'm using MacOS 10.13.5, PyCharm 2018.1.4 CE.

You probably have created a new project using virtualenv, read about it here.
It basically creates a new project specific environment, so the libraries inside won't cause a conflict with python2 and python3 packages. So, inside Pycharm, open terminal by pressing alt+f12 , which will open a terminal inside Pycharm, and install numpy usually by pip install numpy

I don't know why, but when I rebooted the computer and created a new project, this problem has disappeared.

Related

Jupyter Notebook Unable to Load Module mlwpy

I am completely new to programming in general and I do not understand very much about computers. A very similar question was asked previously, however I do not understand anything what was said.
Background: I am attempting to run the first line of code as described in the book Machine Learning with Python for Everyone by Mark Fenner on the Jupyter browser notebook.
This is the code:
In [1]:
from mlwpy import*
%matplotlib inline
Running the code returns this error:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-2-3489a3655c97> in <module>
----> 1 from mlwpy import *
2 get_ipython().run_line_magic('matplotlib', 'inline')
ModuleNotFoundError: No module named 'mlwpy'
From my understanding we need a module mlwpy.py and this module can be found at this link thanks to the author of the book here; https://github.com/mfenner1/mlwpy_code/blob/master/mlwpy.py
However, I do not understand what exactly I am supposed to do with this information. Someone mentioned putting the file in the same directory as our Jupyter notebook.
This is where I am confused, what does that mean exactly? I copied and pasted the text onto Jupyter and then saved it as mlwpy.ipynb in the binder, however the problem continues to remain the same.
If someone could explain step by step what I need to do, that would be greatly appreciated.
mlwpy is not a Python's built-in library, nor an external library you can install with pip or conda. It is a custom python file you would like to import.
To run from mlwpy import *, you need to have a python script named mlwpy.py in the same directory as your Jupyter notebook file.
So download raw.githubusercontent.com/mfenner1/mlwpy_code/master/mlwpy.py and put it in the same directory as your Jupyter notebook. The downloaded file should be named as mlwpy.py.
You also have to check that you're in the correct working directory if running Jupyter. You can import os and print(os.getcwd()) to see if you're in the right place. If not, either put the file in the working directory, or cd to the correct working directory before launching Jupyter.

Using sublime text 3 to edit Anaconda python code on windows

I am trying to run import pandas code via Anacondas' python executable, in sublime text 3, and receive the following error message...
Traceback (most recent call last):
File "C:\<dir>\<python_file>.py", line 1, in <module>
import pandas as pd
File "C:\Users\<>\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\__init__.py", line 19, in <module>
"Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['numpy']
I can import pandas, and run other code when using spyder, but am struggling to get the environment setup in sublime. I have followed the two tutorials below, however I'm not having any luck.
Using Anaconda On Sublime Text (without installing any package)
Anaconda Documentation: Sublime text
any suggestions/advice is much appreciated!
import pandas as pd
It is a bit strange you can import pandas in Spydrr and get an error in Sublime. I cannot give a do-this answer, but I can suggest a review of concepts that you use for diagnostics:
Sublime and Spider are text editors, they are to handle code themselves, but invoke python interpreter that is already installed on the system (eg Anaconda)
sometimes you several python interpreters installed, would need to find out which has a precedence to appear in your path search
same interpreter may work with different virtual environments (package sets), controlled by venv.
From your disgnostic message hard to tell which situation you are in. When in doubt, try play on the command line to run the python.exe and explore your PATH variable.
Hope it helps.

Separate versions of Python on same computer won't import same modules

I've been coding in Python 3.7.2 as my usual, but an API that I really want for my code only supports up to 3.6 (and does not support 2.7). I downloaded Python 3.6.4 to my computer, which also downloads a separate instance of the IDLE (not a problem). If I try to import something like numpy to my code in 3.7 (ex. import numpy as np) then it works as expected. However, if I do the same in the 3.6 IDLE I get:
Traceback (most recent call last):
File "", line 1, in
import numpy as np
ModuleNotFoundError: No module named 'numpy'
I think that it's a path problem but I'm unsure on how to fix it, and I can't find a solution to this problem elsewhere. Any help is appreciated, thanks.
Step 1: Get the location of the python executable from IDLE
import sys
print(sys.executable) # e.g. /Users/jk/.../bin/python
Step 2: Run the pip in the same folder as the one returned above.
/Users/jk/.../bin/pip install numpy
P.S. It's better to maintain libraries independently for each distribution, or even better use virtualenv or conda to create environments.
Try to install numpy specifically for python3.6:
python3.6 -m pip install numpy

Importing CV2 does not work in Spyder but works in PyCharm

I have Anaconda 3 installed (Python 3.6.3) and I am working on a project that uses the CV2 package in python. Now I am relatively new to python but I have been using this package (via "import cv2" command) in PyCharm with no problems. However, today, I wanted to give Spyder a try. I started using the IDE and everything was working. But all of a sudden, Spyder kept giving me an error when I try to import cv2. I really did not change anything and I only was debugging the script. The error I am getting is as follows:
"""
In [1]: import cv2
Traceback (most recent call last):
File "", line 1, in
import cv2
ImportError: DLL load failed: The specified procedure could not be found.
"""
I cannot figure out how this can be related to the IDE since PyCharm still can import it. Could anybody give me a hint please?
As I know CV2 is python 2x related. When You use CV2 You need copy cv2.pyd file directly to python 2x site-packages.

Trying to download modules but python can't find them

So I need some modules for a project and after trying a lot of things and googling a lot of things I still can't get it to work. I used this code to test if the module was working:
import sys
sys.path.append('c:\users\my name\anaconda2\lib\site-packages')
import numpy
x = randn(100,100)
And I got this error:
Traceback (most recent call last):
File "C:\Users\My Name\Desktop\test.py", line 3, in
import numpy
ImportError: No module named numpy
Any idea why I'm doing wrong?
You can try two things:
1) which python
And see what python you are using. You may be still pointing to old python the system has. In that case add ~/anaconda2/bin to $PATH environment variable.
2) sys.path.append('c:\users\my_name\anaconda2\lib\python2.x\site-packages')
Usually anaconda library is installed under lib\pythonx.x(the correct python version number)\site-packages. So change that.
If none of the above worked, then just do clean install from scratch all over again.

Categories

Resources