#๐Ÿ”’ zsh: illegal hardware instruction python -c

253 messages ยท Page 1 of 1 (latest)

summer quarry
#

Having problems with Terminal while installing tensorflow

quasi thistleBOT
#

@summer quarry

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

summer quarry
#

Following this tutorial :

#

Previously I ran the command : pip3 install --ignore-installed --upgrade tensorflow==2.5.0

#

The command I ran right now resulting in this error was :

#

python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

fossil holly
#

whats the python version?

#

whats ur machine architecture?

#

r u using mac?

summer quarry
#

yes

#

Imac

fossil holly
#

wait, u r in mac?

summer quarry
#

Python 3.8.8

summer quarry
#

M1

fossil holly
#

what processor do u have?

summer quarry
#

The M1 is an ARM processor, not an x86 processor. It integrates more components than an Intel CPU. The Apple M1 also integrates RAM in the same package. It features Rosetta 2 dynamic binary translation that allows it to run x86 software.

#

just searched on google

fossil holly
#

can u run this and give me the output?

file $(which python3)
summer quarry
#

/opt/homebrew/bin/python3: Mach-O 64-bit executable arm64

fossil holly
#

ok, uninstall tensorflow in ur machine

summer quarry
#

alright

fossil holly
#

and install it using this

pip3 install tensorflow-macos
summer quarry
#

just gimme a sec

#

also as part of the tutorial

#

i had also installed

#

protobuf

#

should i also uninstall that

#

hey

#

gostops

#

pip3 install tensorflow-macos
ERROR: Could not find a version that satisfies the requirement tensorflow-macos
ERROR: No matching distribution found for tensorflow-macos

vestal charm
#

just want to point out that you guys have mentioned two different executables:

  1. python
  2. python3
summer quarry
#

so

#

should my command have just used python3 -c ...

vestal charm
#

it's up to you to figure out and track which interpreter you're using

fossil holly
#

wait
tensorflow-macos is for py>=3.9

#

amd u r in 3.8

summer quarry
vestal charm
#

when tensorflow says to run "pip" and "python" they don't actually mean that you should type that, they mean that you should run whichever ones of those you intend to do this with

wild scaffold
#

python --version
and
python3 --version
Could help you figure out which versions you have

summer quarry
#

alright

#

so

#

i should upgrade my python

fossil holly
#

i'd say, give it a try

#

and if it didnt work, roll back

summer quarry
#

(base) xxx@iMac ~ % python --version
Python 3.8.8
(base) xxx@iMac ~ % python3 --version
Python 3.9.13

#

look at this

fossil holly
#

alr

vestal charm
#

you should probably not upgrade your python, as your python here probably means a system component that belongs to macos

#

rather, you would install another python that belongs to you

#

you *don't* replace stuff that belongs to the os

summer quarry
#

3.9

#

could i install tensorflow using that

#

but how do i say that i want to use the python3 version

#

its just a pip install

fossil holly
#

yep

#

pip3 it is

summer quarry
wild scaffold
#

python3 -m pip install
maybe?

fossil holly
summer quarry
#

ok lemme just try

summer quarry
wild scaffold
#

nice

summer quarry
#

wait

#

should i have done

#

python3 -m pip3 install

#

?

#

i just did using pip

summer quarry
#

im getting some erros

#

even though they finished

#

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
tensorflow 2.16.2 requires flatbuffers>=23.5.26, but you have flatbuffers 1.12 which is incompatible.
tensorflow 2.16.2 requires keras>=3.0.0, but you have keras 2.9.0 which is incompatible.
tensorflow 2.16.2 requires protobuf!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<5.0.0dev,>=3.20.3, but you have protobuf 3.19.6 which is incompatible.
tensorflow 2.16.2 requires tensorboard<2.17,>=2.16, but you have tensorboard 2.9.1 which is incompatible.
Successfully installed flatbuffers-1.12 keras-2.9.0 protobuf-3.19.6 tensorboard-2.9.1 tensorboard-data-server-0.6.1

#

and some Deprecations as well

wild scaffold
#

I have no idea how to deal with that, sorry

summer quarry
#

np

#

seems like i just have to upgrade or smth

#

idk

fossil holly
#

for now, try creating a venv to install packages

#

and use that venv to run ur tensorflow code

summer quarry
#

Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: module 'tensorflow' has no attribute 'reduce_sum'

fossil holly
#

ur global packages seems to be polluted

summer quarry
#

atleast it doesnt say illegal hardware

summer quarry
#

called

#

tensorflowenv

vestal charm
summer quarry
#

dont have one

#

sait

#

wait

#

so

#

i should do these commands in my venv

vestal charm
#

because if you do, then importing tensorflow would import your tensorflow.py rather than the library

summer quarry
#

how can i get into my venv

#

?

#

like in my terminal im just at base

#

and then i should do

#

python3 -m pip install tensorflow-macos?

#

i guess I will just do it in my vscode terminal

fossil holly
#

if not, you can get into ur venv by running venv-name/Scripts/activate.exe

vestal charm
#

I imagine the activation file might not have .exe in the name

#

it's generally very difficult to tell you exactly what to run because it's your system so it's all relative to how you've set things up and if you don't get it running yourself it's easier to hand you an environment where everything is already set up

summer quarry
#

hey @fossil holly

fossil holly
#

s

summer quarry
#

i changed a few things

#

so

#

i created a new env

#

using conda

#

I fixed all my polluted libraries and upgraded them

#

but still

#
python3 -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
zsh: illegal hardware instruction  python3 -c 
#

HOW

#

why is installation so hard

#

can you help me

#

pls

fossil holly
#

what happened this time?

#

did u install the macos one?

summer quarry
#

yea

fossil holly
#

in the venv right?

summer quarry
#

pip3 install tensorflow-macos==2.12.0

#

i did this

#

coz the errors mentioned

#

about this

#

should I have done python3 -m pip install tensorflow-macos instead?

fossil holly
#

u dont mention the version explicitly

fossil holly
#

also, u said u have conda right?

#

do this too

conda install -c apple tensorflow-deps
vestal charm
#

surely one or the other, not both

summer quarry
#

ok

summer quarry
#

should I still do this one

fossil holly
vestal charm
#

depends on what is responsible for managing your packages. it's gonna be either conda or pip. don't frankenstein it

summer quarry
summer quarry
#

and then pip installed

#

somebody in the github said

#

I'd recommend installing tensorflow-deps using conda first and then installing other stuff using pip.

conda install -c apple tensorflow-deps
pip install -r requirements.txt
requirements.txt containing:

tensorflow-macos
tensorflow-metal
jupyter

other packages

...

#

Thanks for all of your help anyways

fossil holly
#

does it work?

summer quarry
#

I really appreciate it

fossil holly
#

do u get ur issue resolved?

summer quarry
#

still loading

fossil holly
#

whats loading?
are u installing smth?

fossil holly
#

or are u running the python -c command?

#

oh ok

summer quarry
#

i just tried the command

#

last time

fossil holly
#

so, no errors so far?

summer quarry
#

nothings running

#

this is the same as last time when it gave that error

#

hopefully it doesnt this time

#
(tensorflow) xxx@iMac ObjectDetection % python3 -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
#

its just liek this

#

bro its been like this for 2 mins

#

nothings happening

#

what should i do

#

@fossil holly is my program broken?

fossil holly
#

run it in a separate python file

#

and check the output

summer quarry
#

will try

fossil holly
#

i think tasks like this in tf should take a lot of time depending on the machine

summer quarry
#

hm

#

bro

#

honestly

#

imma leave it

#

its just a verification

#

and i can do it later

#

but how do i stop it from running

#

coz

#

when i created a new terminal

#

my

#

tensorflow conda venv

#

was gona

#

gone

fossil holly
#

what?

#

no way

#

do u mena like u lost the venv folder or smth?

#

or u just got out of the venv session?

summer quarry
#
(tensorflowenv) (base) xxx@iMac ObjectDetection % deactivate
(base) xxx@iMac ObjectDetection %     
#

this was the previous venv i had

#

i have no tensorflow folder

#

this is all that is there

#

when i used conda

#

idk if a new folder was even created to begin with

#

conda activate tensorflow

#

just have to do this command to reactivate it

#

but no folder is present

#

is that a problem @fossil holly ?

fossil holly
#

the env folder is still there

summer quarry
fossil holly
#

so, ig no problem for the venv

#

the 3rd one

summer quarry
#

the "tensorflowenv" folder is a venv i created through python

#

the name of my conda env is "tensorflow"

#

and there is no folder fo it

summer quarry
fossil holly
#

doing so will make python to import that folder instead

summer quarry
#

bro look at the steps this tutorial gives

#

which one should I download @fossil holly

vestal charm
#

does your venv actually use the names pip3 and python3? I suspect they define pip and python in the activated environment, so are you even using the correct executables?

#

you've got at least three different environments.. four? you've got conda in there too. and I can't help but wonder if you're blindly copying/guessing instead of using *the. correct. one*

vestal charm
#

and if you're struggling with using a venv, install a trivial package instead to ensure that you're using the venv correctly before moving on to something far more complicated such as tensorflow (which in turn is probably not made easier by doing it on mac and on top of that on arm64)

#

if you can remote into something that has tensorflow installed for you already, that'd save you a whole bunch of trouble

#

having it locally is great and all but imo it's up to you to figure out your environment

summer quarry
#

hey

#

sorry just came onine

vestal charm
#

I got it running on google colab in a few minutes. which mostly consisted of trying to figure out how to even get into colab

#

(no clue why I can run heavy stuff like that for free without any red tape whatsoever but I mean it's there)

summer quarry
#

im pretty sure tensorflow is installed

vestal charm
#

pretty sure?

summer quarry
summer quarry
#

if i did the install

vestal charm
#

well you could import it and look at it

summer quarry
#

and check if it says requirement already satisfied?

vestal charm
#

import tensorflow

#

.....

summer quarry
#

oh sorry

#

i thought you meant i should pip install

vestal charm
#

and again, if you're mixing up environments, start with a trivial package and get that running

summer quarry
#

will try

vestal charm
#

so when you type such a name, you need to ensure that's going to resolve to the thing you meant to run, and not something else

#

you could use the file path yourself, you could read the activation script for the venv to see what it does, or indeed you could run it and query it for who it is

summer quarry
#

hey

#

while

#

i have you here

#

i was simultaneously installing protobuf

vestal charm
#

it's not that it's hard, it's that things don't snap into place. the only one making things work or make sense is you

#

so everything needs to be deliberate from your end

summer quarry
#
(base) xxx@iMac research % protoc object_detection/protos/*.proto --python_out=.
zsh: killed     protoc object_detection/protos/*.proto --python_out=.
vestal charm
#

and now I'm wondering if you're trying to run x86 executables again

#

what if you run your code here instead? https://colab.research.google.com/
looks like you can upload your files there. and tensorflow seems available. no clue what sort of performance is backing that though.

quasi thistleBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.