Can I install solar panels myself or do I need a licensed electrician

Most jurisdictions require licensed electrical work for solar installations because improper wiring creates fire and electrocution hazards. Contact your local building department to learn what your area allows before planning any work.
What homeowners can typically do
You might handle roof preparation, cleanup, or component staging in some areas, but actual electrical connections almost always need a licensed electrician. Even roof mounting often requires proper permitting and inspection. Some states allow homeowners to install systems on their own property if they obtain proper permits and have work inspected.
Permitting reality
Every jurisdiction differs. Some allow owner installed systems with a licensed electrician handling only final connections, while others prohibit it entirely. Attempting unpermitted work voids warranties, creates insurance liability, and delays grid connection. Get written confirmation from your building department and utility company about what's allowed before starting. Professional installation also qualifies you for tax credits in many places, offsetting labor costs.