Running numpy from Pycharm - numpy

I am unable to run numpy in Pycharm BUT works fine in the Terminal. How do I make numpy work in Pycharm?
This is the error message I get in Pycharm
Traceback (most recent call last):
File "/Users/giridhar/PycharmProjects/numpy/testfile", line 12, in <module>
a = np.array([1, 2, 3]) # Create a rank 1 array
AttributeError: module 'numpy' has no attribute 'array'

Update:
It's quite likely that you have a file called numpy.py in another directory.
When you run testfile.py in your terminal, you are inside of your directory 'numpy' which does not have a file numpy.py and that's why it finds the correct numpy-module.
However, in PyCharm you can add directories to Sources Root (i.e. sys.path as explained in this answer) which apparently contains a file called numpy.py. Remove that directory from your sys.path (as explained by jetbrains) and it should also work in PyCharm.
Old answer (wrong!):
As of my knowledge, the directory name does not interfere with module names unless maybe you define your directory as a package using __init__.py
You need to be careful with how you name your directories. It's possible that the Python interpreter uses your directory 'numpy' to find the function 'array()' instead of using the PyPI numpy-module. Re-naming that directory might fix your issue.
So, e.g. "/Users/giridhar/PycharmProjects/my-numpy/testfile"

Related

Import does not function as bat file; but works in spyder

I am still not the most sophisticated python user; but I cannot overcome this probably simple problem. I have a code that works perfectly with the spyder interface. I would like to make it a recurring task via creating a bat file. The bat file which in turn triggers a cmd interface does not import pandas_data reader and the code gets stuck and aborts.
import pandas_datareader.data as web
this line above creates the error below. It's a lengthy text.
File "C:\Users\myself\anaconda3\lib\site-packages\pandas_datareader\__init__.py", line 2, in <module>
from .data import ( File "C:\Users\myself\anaconda3\lib\site-packages\pandas_datareader\data.py", line 9, in <module>
from pandas.util._decorators import deprecate_kwarg File "C:\Users\myself\anaconda3\lib\site-packages\pandas\__init__.py", line 17, in <module>
"Unable to import required dependencies:\n" + "\n".join(missing_dependencies) ImportError: Unable to import required dependencies: numpy:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy c-extensions failed.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
1. Check that you expected to use Python3.7 from "C:\Users\myself\anaconda3\python.exe",
and that you have no directories in your PATH or PYTHONPATH that can
interfere with the Python and numpy version "1.17.0" you're trying to use.
2. If (1) looks fine, you can open a new issue at
https://github.com/numpy/numpy/issues. Please include details on:
- how you installed Python
- how you installed numpy
- your operating system
- whether or not you have multiple versions of Python installed
- if you built from source, your compiler versions and ideally a build log
- If you're working with a numpy git repository, try `git clean -xdf`
(removes all files not under version control) and rebuild numpy.
Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.
Original error was: DLL load failed: The specified module could not be found.

Tensorflow-gpu, has no attribute "python_io"

I am trying to create a custom TFrecords.
When I called a script that uses the tf.python_io.TFRecordWriter(..) as ...:
this error came up
log:
Traceback (most recent call last):
File "createtfrecordsbyother.py", line 105, in <module>
main(args)
File "createtfrecordsbyother.py", line 85, in main
num_shards=num_shards_train)
File "createtfrecordsbyother.py", line 45, in create_tfrecords
with tf.python_io.TFRecordWriter(output_filename) as tfrecord_writer:
AttributeError: module 'tensorflow' has no attribute 'python_io'
Switched to the tensorflow,ver1.15 .
After switching to that version that error is gone and replaced with a warning that states module is depreciated with a new name (io) instead of (python_io)
Note many modules also changed the name.
and downgrading tensorflow may require a updates of CUDA and Cudnn library.
It's not a complete solution to those who wanted to stay in Tensorflow2.0-gpu
But I will post this as a solution for those who are like me fine with downgrade to 1.15.
For uninstall tf,please refer to tf official documentation under install page.

Anaconda install of Tensorflow missing 'audio_ops' from contrib framework

I'm trying to follow along the Audio Recognition Network tutorial.
I've created an Anaconda environment with python 3.6 and followed the install instruction accordingly for installing the GPU whl.
I can run the 'hello world' TF example.
When I go to run 'train.py' in the Audio Recognition Network tutorial/example, I get:
Traceback (most recent call last):
File "train.py", line 79, in <module>
import input_data
File "/home/philglau/speech_commands/input_data.py", line 35, in <module>
from tensorflow.contrib.framework.python.ops import audio_ops as contrib_audio
ImportError: cannot import name 'audio_ops'
The code in the tutorial that fails is:
from tensorflow.contrib.framework.python.ops import audio_ops as contrib_audio
I then backed up that chain until I could import some part of it:
import tensorflow.contrib.framework as test ==> works
import tensorflow.contrib.framework.python as test --> fail:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'tensorflow.contrib.framework' has no attribute 'python'
Not sure where I'm going wrong on my install.
Details:
Ubuntu 16.04
Anaconda env with python 3.6
Followed the 'anaconda' instruction on the TF install page. (GPU version)
I also tried using a python 2.7 env for anaconda but got the same results.
It looks like they're releasing the audio_ops modules in version 1.4 (https://github.com/tensorflow/tensorflow/issues/11339#issuecomment-327879009).
Until v1.4 is released, an easy way around this is to install the nightly tensorflow build
pip install tf-nightly
or with the docker image linked in the issue comment.
The short answer:
The framework is missing the "audio_ops.py" and the example wont work until the file is released. Or you code the wrappers.
More on this:
If you go to the: tensorflow.contrib.framework.python.ops local folder you can find other *_ops.py files but not the "audio_ops.py".
If you get it from the Master at: https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/framework/python/ops
You will find the file is almost empty and with import labels wrong: "audio_ops" vs "gen_audio_ops".
With almost empty I mean that: decode_wav, encode_wav, audio_spectrogram , mfcc are not implemented/wrapped.
So, no working example and no fun.
We need to check again when "audio_ops.py" is released.
Here:
https://github.com/tensorflow/tensorflow/issues/11339
You can find a Developer saying: "we don't actually want to make them public / supported yet. I'm sorry this decision wasn't better documented"

No module named numpy when spark-submitting

I’m spark-submitting a python file that imports numpy but I’m getting a no module named numpy error.
$ spark-submit --py-files projects/other_requirements.egg projects/jobs/my_numpy_als.py
Traceback (most recent call last):
File "/usr/local/www/my_numpy_als.py", line 13, in <module>
from pyspark.mllib.recommendation import ALS
File "/usr/lib/spark/python/pyspark/mllib/__init__.py", line 24, in <module>
import numpy
ImportError: No module named numpy
I was thinking I would pull in an egg for numpy —python-files, but I'm having trouble figuring out how to build that egg. But then it occurred to me that pyspark itself uses numpy. It would be silly to pull in my own version of numpy.
Any idea on the appropriate thing to do here?
It looks like Spark is using a version of Python that does not have numpy installed. It could be because you are working inside a virtual environment.
Try this:
# The following is for specifying a Python version for PySpark. Here we
# use the currently calling Python version.
# This is handy for when we are using a virtualenv, for example, because
# otherwise Spark would choose the default system Python version.
os.environ['PYSPARK_PYTHON'] = sys.executable
I got this to work by installing numpy on all the emr-nodes by configuring a small bootstrapping script that contains the following (among other things).
#!/bin/bash -xe
sudo yum install python-numpy python-scipy -y
Then configure the bootstrap script to be executed when you start your cluster by adding the following option to the aws emr command (the following example gives an argument to the bootstrap script)
--bootstrap-actions Path=s3://some-bucket/keylocation/bootstrap.sh,Name=setup_dependencies,Args=[s3://some-bucket]
This can be used when setting up a cluster automatically from DataPipeline as well.
Sometimes, when you import certain libraries, your namespace is polluted with numpy functions. Functions such as min, max and sum are especially prone to this pollution. Whenever in doubt, locate calls to these functions and replace these calls with __builtin__.sum etc. Doing so will sometimes be faster than locating the pollution source.
Make sure your spark-env.sh has PYSPARK_PATH pointing to the correct Python release. Add export PYSPARK_PATH=/your_python_exe_path to /conf/spark-env.sh file.

Error with PyQtDeploy

I'm using PyQt 5.3.1 and I'm deploying with pyqtdeploy 0.4 and when i want to build a project i obtain this error message:
Generating code...
Cleaning E:\ProgramasPython3\PythonQT\QTCalculator\build.
Freezing C:\Users\Tobal\AppData\Local\Temp\bootstrap_py3.py
Freezing E:\ProgramasPython3\PythonQT\QTCalculator\qtcalculator.py
Freezing E:/ProgramasPython3/PythonQT\QTCalculator\__init__.py
Freezing E:/ProgramasPython3/PythonQT\QTCalculator\calculator_ui.py
Freezing E:/ProgramasPython3/PythonQT\QTCalculator\img_rc.py
Freezing E:/ProgramasPython3/PythonQT\QTCalculator\qtcalculator.py
Freezing C:\Python34\libs\site-packages\PyQt5\__init__.py
Unable to freeze C:\Python34\libs\site-packages\PyQt5\__init__.py.
Traceback (most recent call last):
File "C:\Users\Tobal\AppData\Local\Temp\freeze.py", line 103, in <module>
freeze_as_data(py_file, options.as_data)
File "C:\Users\Tobal\AppData\Local\Temp\freeze.py", line 36, in freeze_as_data
code = _get_marshalled_code(py_filename)
File "C:\Users\Tobal\AppData\Local\Temp\freeze.py", line 71, in _get_marshalled_code
source_file = open(py_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Python34\\libs\\site-packages\\PyQt5\\__init__.py'
I think this is a bug. someone does know how to fix it?
Thanks
Did you build PyQt5 statically? The host and target Python are two different things, and often in different directories. The target Python has PyQt module built statically, the host Python must also have PyQt5 installed (because pyqtdeploy uses Qt for its GUI) but its usually a dynamic library in the host Python.
In the pyqtdeploy GUI on "Locations" tab, make sure that "Standard library directory" is correct.